/    Sign up×
Community /Pin to ProfileBookmark

unknown error..

hi guys,

i am trying to write a code that can actually get a value from one table and then use that value to run another SQL query,,, hmm.. i dun really know how to explain but i hope u guys can help..

can u guys help me to check why when i use something like $info.$i, it doesn’t have any value inside ? did i miss something here ? did i insert the variables wrongly ? can you guys let me know how i suppose to write in order to get the value i want .. i actually want it to loop for 10 times since i have 10 records for a user in page_info table.

this is the code that i wrote :

[CODE]
<?
// connect to db
include “../include/global.php”;

// navigation menu
$query2 = mysql_query(“SELECT * FROM `sorting` where `site_name` = ‘$site_name'”) or die(“Error occured”);
$row2 = mysql_fetch_array($query2);

for( $i = 1; $i < 11 ; $i++)
{
$info.$i = mysql_query(“SELECT * FROM page_info where `site_name` = ‘$site_name’ AND id = ‘{$row2[‘sort$i’]}'”) or die(“Error occured”);

$display.$i = mysql_fetch_array($info.$i);
//echo “$info.$i”;
//echo “|| $display.$i”;
}

echo $display1[‘name’];
echo $display2[‘name’];
..
.

?>
[/CODE]

there is no output displayed and i received an error saying Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource.

please advise.. thanks.

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@scragarJan 20.2005 — the error is yours:

Variables must not have a name which is a portion of an earlier variable (OR have a name which holds an extension to that of an earlier variable)or it's content's will be unretivable:

$alpha = "ABCDEF";

$a = "CAT";

$alpha; // $aplha is now taken to be CATlpha which is invalid syntax.
Copy linkTweet thisAlerts:
@AliciaauthorJan 20.2005 — hi,

can you give me some idea how should i amend my code (variable) in order to accomplish what i want ?

i can't figure out anyway except combine two variables together which i should shouldn't work..

really need ur guys advice.. thanks in advance.
Copy linkTweet thisAlerts:
@NogDogJan 20.2005 — [i]Originally posted by scragar [/i]

[B]the error is yours:



Variables must not have a name which is a portion of an earlier variable (OR have a name which holds an extension to that of an earlier variable)or it's content's will be unretivable:

$alpha = "ABCDEF";

$a = "CAT";

$alpha; // $aplha is now taken to be CATlpha which is invalid syntax. [/B]
[/QUOTE]

Really?

I just tried this, worked fine:
[code=php]
<?php
$alpha = "ABCDEF";
$a = "CAT";
echo "<p>$alpha</p>n";
$b = "DOG";
$bravo = "UVWXYZ";
echo "<p>$bravo</p>n";
?>
[/code]
Copy linkTweet thisAlerts:
@scragarJan 21.2005 — That's because when echoing something out that's in quotes it uses the largest version possible, yet when using variables normaly, depending on your version, it may or may not acnowledge the $index as $i.

A quick fix is to just replace $index with $Index.



The code I posted came from a C++ tutorial and as most people know C++ is the codebase for PHP...
Copy linkTweet thisAlerts:
@NogDogJan 21.2005 — [i]Originally posted by scragar [/i]

[B]That's because when echoing something out that's in quotes it uses the largest version possible, yet when using variables normaly, depending on your version, it may or may not acnowledge the $index as $i.



A quick fix is to just replace $index with $Index.







The code I posted came from a C++ tutorial and as most people know C++ is the codebase for PHP... [/B]
[/QUOTE]

Hmmm...maybe they fixed this in later versions? All I know is I've never run into this problem (as far as I know! :rolleyes: ), and I've done stuff on PHP3 through PHP 4.8.3. Oh well, "Forewarned is fore-armed," so now I'll know something else to look for when some bizarre bug shows up one day. ?
Copy linkTweet thisAlerts:
@scragarJan 26.2005 — what I tend to do is start all my variables with something like:

[code=php]<?
$c_i = 5;
//the i is what I use to identyfie that it should be an int.
// now If I try:
$cont_i = 7;
//there is no chance of cont being mistook for c since the extra _i is not there.

/* also use:
_i for int's
_s for string
_y for system objects
_f for floating points
_v for variants(disliked!)
_r for regexp.
_r for record sets
_f for file indexes(as in fopen)
_b for boolean
*/[/code]
Copy linkTweet thisAlerts:
@AliciaauthorJan 31.2005 — Hi guys,

it is still not working..

my sorting table structure :
[CODE]

CREATE TABLE sorting (
username varchar(20) NOT NULL default '',
site_name varchar(20) NOT NULL default '',
sort1 char(5) NOT NULL default '',
sort2 char(5) NOT NULL default '',
sort3 char(5) NOT NULL default '',
sort4 char(5) NOT NULL default '',
sort5 char(5) NOT NULL default '',
sort6 char(5) NOT NULL default '',
sort7 char(5) NOT NULL default '',
sort8 char(5) NOT NULL default '',
sort9 char(5) NOT NULL default '',
sort10 char(5) NOT NULL default ''
) TYPE=MyISAM;

[/CODE]



my page_info table structure :
[CODE]
CREATE TABLE page_info (
username varchar(20) NOT NULL default '',
site_name varchar(20) NOT NULL default '',
id int(2) NOT NULL default '0',
page_name varchar(50) NOT NULL default '',
file_name varchar(50) NOT NULL default '',
status varchar(10) NOT NULL default ''
) TYPE=MyISAM;
[/CODE]


what i wan to do is something like what most website creator application can do for the page sorting.. i am thinking to do something like that too.. so i thought the flow can be like this :

// fetch the record from 'sorting' table to get the page arrangement information

for ur information, sort(x) in sorting table is used to store page id

// after that, i will use for loop to get the information of the page, like page name, file name and etc based on the sort(x) value : page id info..


I have tried many ways but it is not working.. it will be great if you guys can advise what method i can use to accomplish this.. or let me know what i have done wrong in my coding..

is there any references available online ?

thanks..
×

Success!

Help @Alicia spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...