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>';
}
?>
No comments posted yet
Your Answer:
Login to answer
348
25
Other forums
Will an XHTML DOCTYPE interfere with my PHP if I'm not experienced enough?
I've read this article here: http://friendlybit.com/html/why-xhtml-is-a-bad-idea/
In a nutshe
Help please - How to validate from 2 possible answers
Hi
I hope somebody can help me with what will probably be really simple, I'm pulling my hair
Email "$"
Hello!!
Any PHP guy with a bit of a knowledge in Flash ?
When I send a JPEG from flash
Help pulling in 'id' with "read more" link
I'm trying to create snippets of my articles in the cms I'm creating, and then have them redirect to
Is there a more efficient way to code this than what I have?
I have three associative arrays.
$combinedSettings
$userSettings
$defaultSettings
SWF image using php?
Hello once again.
My latest en devour requires me to produce an image of a static .swf that i
How to show more than 1 users with this code...
Hello,
i have a table that shows users only if I, as Administrator, want to be shown. But its sho
storing video files into mysql in php
hi
i have my video files in my folder ,
i have to store the path of the videos into db an
Unable to display contents in Second Drop Down Box
Hi All,
What I am trying to do is 2 dependent drop down boxes and when user selects su
Most basic form question ever?
Hello,
I want to use this snippet to make sure the fields in a form are ok before processing