Jump to content

Recommended Posts

Hello there I've got two questions that I hope you can help me with

 

firstly as you can see here I've got a loop which makes a list of links out of the id field and name fields of my database

 

<?php
      $result = mysql_query("SELECT `id`,`name` FROM linkvideos_category");
  
      while($row = mysql_fetch_assoc($result)){

echo'
     <a class="categorylink" href="'.$web_path.'video_listing.php?category='.$row['id'].'">'.$row['name'].'</a>

<br />
<img src="'.$pro_path.'/images/box_middle_line.jpg"  />

';
}
?>

 

Now I want the loop on the last iteration not to output that image and I'm not sure how

 

 

& lastly I input a new name and id into my database but its not being reflected in my code, is there any reason why it wouldn't be updating and appending my new item to this list when I run the website?

 

Thanks for your time, arcanine.

 

ps what does that $result string do exactly? I've modified the code from a tutorial I found

Link to comment
https://forums.phpfreaks.com/topic/149030-last-itteration-of-a-loop/
Share on other sites

I was modifying the wrong table haha thanks I wouldn't have looked otherwise, okay I've taken a shot at what you said but please keep in mind I'm not a php coder by a long stretch

<?php
      $result = mysql_query("SELECT `id`,`name` FROM linkvideos_category");
$num_rows = mysql_num_rows($result);

      while($row = mysql_fetch_assoc($result)){

if ($num_rows != 0 ){
$num_rows--;

echo'
     <a class="categorylink" href="'.$web_path.'video_listing.php?category='.$row['id'].'">'.$row['name'].'</a>

<br />
<img src="'.$pro_path.'/images/box_middle_line.jpg"  />}
';
else { 
echo'
     <a class="categorylink" href="'.$web_path.'video_listing.php?category='.$row['id'].'">'.$row['name'].'</a>}
';

}
?>

 

I think it says if $num_rows isn't 0 (so isn't on the last iteration)  then output as normal else output without the image

it was zero in the end

 

had a bit of trouble with it but got there in the end for those interested finished code was:

 

 <?php
$result = mysql_query("SELECT `id`,`name` FROM linkvideos_category");
$num_rows = mysql_num_rows($result);
while($row = mysql_fetch_assoc($result)){
$num_rows--;
if ($num_rows != 0 ){
echo'
     <a class="categorylink" href="'.$web_path.'video_listing.php?category='.$row['id'].'">'.$row['name'].'</a>
<br />
<img src="'.$pro_path.'/images/box_middle_line.jpg"  />';
}
else { 
echo'     <a class="categorylink" href="'.$web_path.'video_listing.php?category='.$row['id'].'">'.$row['name'].'</a>';
}}
?>

 

Thanks a lot for your help guys

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.