0

sorry to ask twice, but the other one was closed because it was missing important info and i apologize however my code is this:

if (isset($_GET['id'])) {
// Connect to the MySQL database  
include "connect.php"; 
$id = preg_replace('#[^0-9]#i', '', $_GET['id']); 
// Use this var to check to see if this ID exists, if yes then get the bio info 
$sql = mysql_query("SELECT * FROM bio\n"
. "LEFT JOIN bio_media \n"
. "ON bio.id=bio_media.bioid\n"
. "WHERE bio.id = ".$id."\n"
. "\n"
. " LIMIT 0, 30 ");
    // get all the bio details
    while($row = mysql_fetch_array($sql)){ 
         $name = $row["name"];
         $age = $row["age"];
         $division = $row["division"];
         $pic = $row["pic"];
         $story = $row["story"];
         $fb = $row["fb"];
         $tw = $row["tw"];
         $type = $row['type'];
         $file = $row['file'];
         $alt = $row['alt'];
         $title = $row['title'];
         $Age= DetermineAgeFromDOB ($age);
         while ($type == "image"){
                $images .='<a rel="lb[pp_gal]" href="images/'.$file.'" ><img width="60px" alt="'.$alt.'" title="'.$title.'" src="images/'.$file.'" /></a>';     
                break;
                }
        $i=-1;
        if($type == "video"){
            $i++;               
            $videos .='<li><a href="watch.php?id='.$id.'&v='.$file.'&ref='.$i.'?iframe=true&width=745&height=520" rel="lb" title="'.$alt.'">'.$title.'</a></li>';
            }

Question: How do i get the "ref" portion of the url to update +1 for each entry in the database?

5
  • the ref portion of the url is not iteration it just goes to 0 Commented Sep 2, 2011 at 20:46
  • Use this, instead of preg_replace(): if ( ! ctype_digit($_GET['id'])) die('Invalid input'); else $id = (int) $_GET['id']; Commented Sep 2, 2011 at 20:49
  • 1
    ... you set $i to be -1, then increment it once - it will always be 0 in that case, yes. Commented Sep 2, 2011 at 20:51
  • webbiedave, it shows on mine but the code is: if($type == "video"){ $i++; $videos .='<li><a href="watch.php?id='.$id.'&v='.$file.'&ref='.$i.'?iframe=true&width=745&height=520" rel="lb" title="'.$alt.'">'.$title.'</a></li>'; } for all the entrys that come out, it shows the ref=0 it only adds to $i once Commented Sep 2, 2011 at 20:52
  • $i=-1; << might be the problem? Commented Sep 2, 2011 at 20:54

1 Answer 1

2

If I understand you correctly, you have to get rid of $i=-1; in the loop and just put $i=0; before the loop.

By the way, you are overwriting your variables in the loop every time; either just add $row to an array and use that or don´t use these temporary variables at all and just use $row directly where you need it.

Sign up to request clarification or add additional context in comments.

2 Comments

If i use $i=0 it then makes all of the ref=1. i need it to count for each one. could you be a little more specific with what you mean as far as $row?
@Symply No, you need to set $i to 0 before your while loop (the outer one).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.