|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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'];
..
.
?>
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. |
|
#2
|
||||
|
||||
|
$info.$i is likely to cause an error
Perhaps you should make it an array... Simply use: $info[] = mysql_query(whatever) I don't quite understand what your second query is accomplishing... all the results would be the same, no? $site_name isn't changing anywhere. And are you always going to loop 10 times? |
|
#3
|
|||
|
|||
|
yes,, i definitely need to loop 10 times..
actually in the first query, i want to get the information of which page to be displayed first,, then in the second query, i want to display the page name according to the results obtained from the first query (sort the id : ascending).. i am very weak in array,, do u mind to explain a little bit more how to use the array in my case ?? really appreciate for giving me advicess.. thanks.. |
|
#4
|
||||
|
||||
|
Can you give us a little more info on your table structure and perhaps some sample data?
Maybe then we'll fully understand your question and therefore be able to suggest a more efficient way of doing this... Maybe present a modified code, if you tried using the array already... |
|
#5
|
|||
|
|||
|
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; 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; 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.. thanks.. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > unknown error.. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|