tcorbeil Posted March 29, 2007 Share Posted March 29, 2007 I am having trouble with this code: $database = "oilers" $query="SELECT * FROM '$database' WHERE Page = '$pagepath'"; Even though I know I have a table in my database called oilers, it doesn't seem to work.. I'm thinking it is just my syntax using the variable $database.. can someone let me know if there is something wrong? Thanks everyone. T. Link to comment https://forums.phpfreaks.com/topic/44728-proper-syntax/ Share on other sites More sharing options...
ultrus Posted March 29, 2007 Share Posted March 29, 2007 Hmmm. Try this: $query="SELECT * FROM '" . $database . "' WHERE Page = '" . $pagepath . "'"; Variables inside of single quotes have been giving me troubles today. With my frustration today anyway, echo('Are you happy?: $happy'); would output: Are you happy?: $happy With double quotes - echo("Are you happy?: $happy"); Are you happy?: Yes! Link to comment https://forums.phpfreaks.com/topic/44728-proper-syntax/#findComment-217152 Share on other sites More sharing options...
btherl Posted March 29, 2007 Share Posted March 29, 2007 Table names shouldn't be inside ' , instead they should be inside ` , or inside no quotes at all. Link to comment https://forums.phpfreaks.com/topic/44728-proper-syntax/#findComment-217155 Share on other sites More sharing options...
ultrus Posted March 29, 2007 Share Posted March 29, 2007 Ah yes. My code above is bunk. $query="SELECT * FROM $database WHERE Page = '" . $pagepath . "'"; Link to comment https://forums.phpfreaks.com/topic/44728-proper-syntax/#findComment-217159 Share on other sites More sharing options...
tcorbeil Posted March 29, 2007 Author Share Posted March 29, 2007 Ok i tried: $database = "Tim_123"; $query="SELECT * FROM $database WHERE Page = '".$pagepath."'"; ...still no go.. I can't think of anything else to try.. seems I tried every different syntax variations and no go.. Any other ideas before I pull my hair out? T. Link to comment https://forums.phpfreaks.com/topic/44728-proper-syntax/#findComment-217165 Share on other sites More sharing options...
ultrus Posted March 29, 2007 Share Posted March 29, 2007 what is the error you are getting? If you pull your hair out, I recommend using this php class: http://www.phpclasses.org/browse/package/790.html It helps on my rush projects. Link to comment https://forums.phpfreaks.com/topic/44728-proper-syntax/#findComment-217168 Share on other sites More sharing options...
tcorbeil Posted March 29, 2007 Author Share Posted March 29, 2007 Ok maybe I'm on the wrong track... I'm getting this error: Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/tcorbeil/public_html/Entertainment/Tim_123/Tim_123.php on line 897 with this code: $database = "Tim_123"; $query="SELECT * FROM $database WHERE Page = '".$pagepath."'"; $result=mysql_query($query); $num=mysql_numrows($result); it seems the error would have to do with the numrow.. I use $num=mysql_numrows($result); to count the amount of occurences in the search... T. Link to comment https://forums.phpfreaks.com/topic/44728-proper-syntax/#findComment-217170 Share on other sites More sharing options...
Lytheum Posted March 29, 2007 Share Posted March 29, 2007 Should be $result = mysql_num_rows($result); I do believe. Link to comment https://forums.phpfreaks.com/topic/44728-proper-syntax/#findComment-217172 Share on other sites More sharing options...
hitman6003 Posted March 29, 2007 Share Posted March 29, 2007 change: $result=mysql_query($query); to $result=mysql_query($query) or die(mysql_error()); And see what the error is. Link to comment https://forums.phpfreaks.com/topic/44728-proper-syntax/#findComment-217176 Share on other sites More sharing options...
trq Posted March 29, 2007 Share Posted March 29, 2007 Firstly, get in the habbit of checking your queries actually work before trying to use them, the code you posted is extremely error prone. <?php // connect to db. $database = "Tim_123"; $query = "SELECT * FROM $database WHERE Page = '$pagepath';"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_assoc($result)) { print_r($row); } } else { echo "No results found."; } } else { echo "Query failed. $query<br />" . mysql_error(); } ?> Secondly... where is $pagepath defined? Link to comment https://forums.phpfreaks.com/topic/44728-proper-syntax/#findComment-217177 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.