Click to See Complete Forum and Search --> : unknown error..
Alicia
01-20-2005, 07:35 AM
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 :
<?
// 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'];
..
.
?>
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.
scragar
01-20-2005, 07:42 AM
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.
Alicia
01-20-2005, 08:50 AM
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.
NogDog
01-20-2005, 08:58 AM
Originally posted by scragar
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.
Really?
I just tried this, worked fine:
<?php
$alpha = "ABCDEF";
$a = "CAT";
echo "<p>$alpha</p>\n";
$b = "DOG";
$bravo = "UVWXYZ";
echo "<p>$bravo</p>\n";
?>
scragar
01-21-2005, 03:07 AM
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...
NogDog
01-21-2005, 09:24 AM
Originally posted by scragar
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...
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. :)
scragar
01-26-2005, 04:08 AM
what I tend to do is start all my variables with something like:
<?
$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
*/
Alicia
01-30-2005, 11:33 PM
Hi guys,
it is still not working..
my sorting table structure :
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;
my page_info table structure :
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;
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..