IF Statement & Two Tables With Different Echoes
Posted on
16th Feb 2014 07:03 pm by
admin
I'm retrieving two tables in a single query using UNION ALL, like so:
Code: $query = "SELECT * FROM film UNION ALL SELECT * FROM people ORDER BY id DESC LIMIT 5 ";
Now each of those tables, FILM and PEOPLE create links to two different pages for the different information stored in the said tables. Here are the two different echoes for the tables:
FILM:
Code: <li><a href="filmography.php?title='.$title.'"><img src="images/thumbnails/'.$image.'.jpg" alt="" title="'.$title.' ('.$year.')"></a></li>
PEOPLE:
Code: <li><a href="biography.php?name='.$name.'"><img src="images/thumbnails/'.$img.'.jpg" alt="" title="'.$name.' ('.$occupation.')"></a></li>
Is there an IF statement, or anything else for that matter, which will identify which table each row comes from and then assign the necessary link to that row, like so?:
Quoteif (row belongs to (FILM)) {
echo '<li><a href="filmography.php?title='.$title.'"><img src="images/thumbnails/'.$image.'.jpg" alt="" title="'.$title.' ('.$year.')"></a></li>';
}
else echo '<li><a href="biography.php?name='.$name.'"><img src="images/thumbnails/'.$img.'.jpg" alt="" title="'.$name.' ('.$occupation.')"></a></li>';
Here's my poor attempt at managing it (obviously doesn't work):
Code: <?php
mysql_connect(localhost,user,pw);
@mysql_select_db(db) or die( "Unable to select database");
$query = "SELECT * FROM film UNION ALL SELECT * FROM people ORDER BY id DESC LIMIT 5 ";
$result = mysql_query( $query ) or die(mysql_error());
while ($row = mysql_fetch_array($result))
{
extract($row);
$field_array = mysql_fetch_array($result);
if (!in_array(`img`, $field_array)) {
echo '<li><a href="filmography.php?title='.$title.'"><img src="images/thumbnails/'.$image.'.jpg" alt="" title="'.$title.' ('.$year.')"></a></li>';
}
else echo '<li><a href="biography.php?name='.$name.'"><img src="images/thumbnails/'.$img.'.jpg" alt="" title="'.$name.' ('.$occupation.')"></a></li>';
}
?>
348
25
Other php-forum
Drawing Images in classes
I'm quite new to Object Oriented PHP. What I'm trying to do is draw some images but also have other
Read from forum
Haven't written anything forever and I would like to get back.
What I'm trying to do is getting t
Getting a variable to work in function params
I have this fuction which is inside a class:
Code: public static function generateEmbedCode($
OOP help
okay so i have a class im making it has everything setup i just need to randomize the 2 variables an
Prevention Help
How can I use PHP or any other language (feel free to move this thread) to prevent users doing scree
Simple AND question
Hello,
I've got following code:
Code: if(strpos($row[13],"http://")
Retrieving Data from Two Different Databases
Hello All,
Ran into another problem and would appreciate some help! I have two datab
Parse XML
Good day,
I use oempro software and try to parse XMLReturn but it's not working for me, simpl
How do I give a developer access to a specific directory and nothing else?
I want to give a develop access to a specific directory and nothing else
I can give them an F
Structure Question - One Table or One Table Per Record Set?
I have a web app (mySQL and PHP) which allows people to create an item with up to 200 records which