sturgess1987 Posted November 9, 2008 Share Posted November 9, 2008 Hi guys, this is my first post here and im hoping someone can save me! Im cuurently creating a project at university in which users can upload various content including video and photos, now the only issue im havig is once these items have been uploaded, i dont know how to display them correctly in the gallery page. Basically i want the gallery to display all uploaded content by its id, so the order in which its uploaded, so the problem im having is how to write the nested if statement that works out if the next upload is an image or a video. this is my code thus far... <? $query = "SELECT * FROM gallery ORDER BY id"; $result = mysql_query($query, $db) or die("error"); $num = mysql_num_rows($result); mysql_close($db); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> <script src="js/jquery.pack.js"></script> <script src="js/flashembed.min.js"></script> <script src="js/flow.embed.js"></script> <link rel="stylesheet" type="text/css" href="css/common.css" /> <link rel="stylesheet" type="text/css" href="css/multiple-instances.css"/> <script> // this simple call does the magic $(function() { $("a.flowplayer").flowembed("FlowPlayerLight", {initialScale:'scale'}); }); </script> </head> <body> <h1> There are <? echo $num; ?> items in this gallery </h1> <? while ($array = mysql_fetch_assoc($result)) { ?> <p> Image uploaded by <? echo $array['name']; ?></p> <a href="display.php?id=<? echo $array['id']; ?>"></a> <p> <a class="flowplayer" href="<? echo $array['video']; ?>"> <img src="img/2m.jpg" /> </a> <p> <? echo $array['description']; ?> </p> </p> as you can see ive called the video up from the database, but am not sure how to write it so that if the next id was a photo it would show that next. thanks in advance for any help given. <? } ?> Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted November 9, 2008 Share Posted November 9, 2008 First,use code tags, and second what does the if statement need to do. Quote Link to comment Share on other sites More sharing options...
sturgess1987 Posted November 9, 2008 Author Share Posted November 9, 2008 sorry will do next time, the if statement needs to look at my gallery table in my database and see if the next 'id' is a photo or a video then display the correct one on my gallery page. sorry if its not making much sense Quote Link to comment Share on other sites More sharing options...
bobbinsbro Posted November 9, 2008 Share Posted November 9, 2008 well, how do you indicate whether the next id is a photo or a video in the DB? Quote Link to comment Share on other sites More sharing options...
sturgess1987 Posted November 9, 2008 Author Share Posted November 9, 2008 there are two fields within my gallery table, one called video and one called image, so i just need to know how i would go about picking that out Quote Link to comment Share on other sites More sharing options...
bobbinsbro Posted November 9, 2008 Share Posted November 9, 2008 on a video row, is the pic column null or is there some other default value? Quote Link to comment Share on other sites More sharing options...
sturgess1987 Posted November 9, 2008 Author Share Posted November 9, 2008 its null, and the same goes the other way round, so on photo the video column is null also Quote Link to comment Share on other sites More sharing options...
bobbinsbro Posted November 9, 2008 Share Posted November 9, 2008 change this line: <p> <a class="flowplayer" href="<? echo $array['video']; ?>"> <img src="img/2m.jpg" /> </a> to this: <p> <a class="flowplayer" href="<? echo is_null($array['video'])?$array['picture']:$array['video']; ?>"> <img src="img/2m.jpg" /> </a> change the array index of 'picture' the the correct column name. test, and report back. if there is a different class for picture and video anchors, do this instead: <? while ($array = mysql_fetch_assoc($result)) { ?> <p> Image uploaded by <? echo $array['name']; ?></p> <a href="display.php?id=<? echo $array['id']; ?>"></a> <?php if is_null($array['picture']){ ?> <p> <a class="flowplayer" href="<? echo $array['video']; ?>"> <img src="img/2m.jpg" /> </a> <?php } else{ ?> #########put the picture anchor here############ <?php }//close else block ?> <p> <? echo $array['description']; ?> </p> </p> <?php } ?> Quote Link to comment Share on other sites More sharing options...
sturgess1987 Posted November 9, 2008 Author Share Posted November 9, 2008 thanks, i will try it out and test it, will let you know if it all works ok. Quote Link to comment Share on other sites More sharing options...
mattal999 Posted November 9, 2008 Share Posted November 9, 2008 Have you even connected to the database? Quote Link to comment Share on other sites More sharing options...
sturgess1987 Posted November 9, 2008 Author Share Posted November 9, 2008 yes i have i just didnt want to post my database info into the post, ive tried it and am getting the following syntaz error Parse error: syntax error, unexpected T_STRING, expecting '(' in /home/jsturgess/public_html/gallery.php on line 57 its referring to the line if is_null ($array['image']){ ?> Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted November 9, 2008 Share Posted November 9, 2008 if is_null ($array['image']){ ?> should be if (is_null($array['image'])){ ?> Quote Link to comment Share on other sites More sharing options...
sturgess1987 Posted November 9, 2008 Author Share Posted November 9, 2008 Fantastic it works!, thanks everyone, especially bobbinsbro. Much appreciated. Quote Link to comment Share on other sites More sharing options...
bobbinsbro Posted November 9, 2008 Share Posted November 9, 2008 no problem. please set topic to solved. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.