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
Bar charts using Graphical Framework.
I am using Graphical Frameworks(GFW) to create a chart Graphic . There is no problem with the data d
urldecode question
How would I format this line of code properly?
<?php echo urldecode($_GET['Title']); ?
PHP/Database issue
My friend is helping me make a database where you go to a certain webpage of my site and the page wi
i want run some web server under the ip sharer
hello i want run some web server under the ip sharer
my ip is floating ip but it doesnt matter
single page with referrer to show correct page
I have a simple website with a couple of different pages. I would like to be able to in a div tag w
PHP Upload issue
Hi guys,
I have stumble across an interesting issue with my script and is doing my head in.
Need help with an email blocker for a guessbook
I am new with php and here is a simple guessbook page but I am being hit with spam from a group of t
Email to a friend script problems
I have this send-to-a-friend script with 2 issues:
1) When you open the form popup on a p
Need help/w Page: 1,2,3,4 function!
So I have this code im working on where it's ment to display seperate pages having 20 logs each
I
ORA-01655: unable to extend cluster SYS.C_FILE#_BLOCK# by 128
Hi all,
Oracle 10g. Linux.
I'm facing the below error while trying to import a dumpfil