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
Nested (echoed) php running wrong script
Got a problem with a php website I'm creating.
In a nutshell, the first page is entirely html
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
Procedural to OOP
ohn Kleijn said that to avoid writing "crappy code", we should learn OOP and common OO pri
PDO returns erroneous columns from within pdt
Hi All,
This is a truly weird behavior:
When using a simple pdo fetch, erroneous columns a
passing data from one page to another
hey guys
i have the follwoing code to get information from one page and place on another:
using variables in another page
I have a test database set up on localhost. I have a form that I can type a name into, hit the butto
How to extract/download content from HTTPS page?
Hello to all the Members of this forum, Im Shoiab, A novice programmer in php.. for my first job I h
Hashing?
Hi, I was hoping to take a string value then convert it - consistently - across each of our pages in
Help adding strtolower( to my in_array
strtolower i need to add it to this to work, iuno how.
Code: $moderators = array('Admin', 'ba
How to login with SAPCPIC userid
I have changed the Password for SAPCPIC in Development Server for 000,001 and 100 client.
But w