Jump to content

Proper Syntax


tcorbeil

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.