Jump to content

[SOLVED] Please help, PHP MYSQL issue.


sturgess1987

Recommended Posts

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.

 

<? } ?>

 

 

Link to comment
Share on other sites

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 } ?>

Link to comment
Share on other sites

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']){ ?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.