Page 1 of 1

Does this simple select and echo look right?

Posted: Sat Jul 10, 2004 12:23 am
by tsm4781

Code: Select all

<?php
include ("db.inc.php");

$query = "SELECT * FROM fpannounce";
$query2 = "SELECT * FROM content WHERE pagetitle='index'";
$result = mysql_query($query) or die("Whoops! Something wrong happened to the my database!");
$result2 = mysql_query($query2) or die("Whoops! Something wrong happened to the my database!");

if ($result && $result2) 
{
  while ($r = mysql_fetch_array($result && $result2)) 
    {
    extract($r);
    echo "<div id="sidebar">$announce</div>";
    echo "$body";
    }
  mysql_free_result($result && $result2);
}

mysql_close();
?>
I get the following errors in my file.....

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/tstowell/public_html/dev/index.php on line 130

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/tstowell/public_html/dev/index.php on line 136

Thoughts??

Posted: Sat Jul 10, 2004 2:07 am
by kettle_drum
Dont know if you can have two resource results in mysql_fetch_array like that.

Posted: Sat Jul 10, 2004 4:44 am
by feyd
continuing kettle_drum's thoughts: you can't use fetch_array with that syntax.. && results in a boolean value.

Posted: Sat Jul 10, 2004 10:07 am
by tsm4781
Ok.. so if I want to do a select from a table and print the HTML code that I have input in a field, what would be the best way to lay out the code. Obviously I am doing something wrong here to get those errors.

Posted: Sat Jul 10, 2004 10:32 am
by feyd
you'll probably need to go through each query individually, either storing the data into an array, so you can combine them later, or just writing them out as you read them...

Posted: Sat Jul 10, 2004 12:07 pm
by kettle_drum
Or you select data from both databases in the same query:

Code: Select all

SELECT table.*, table2.* FROM table, table2 WHERE table2.field = 'blah';