Does this simple select and echo look right?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tsm4781
Forum Commoner
Posts: 38
Joined: Wed Jul 09, 2003 7:17 pm

Does this simple select and echo look right?

Post 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??
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Dont know if you can have two resource results in mysql_fetch_array like that.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

continuing kettle_drum's thoughts: you can't use fetch_array with that syntax.. && results in a boolean value.
tsm4781
Forum Commoner
Posts: 38
Joined: Wed Jul 09, 2003 7:17 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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...
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post 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';
Post Reply