SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    reset multidimensional array

    Hi All,

    I am doing some simple (so I thought) query and display work. I have this code

    Code:
    //mySql query
                 $qry = "SELECT * FROM playlist WHERE `date` = '$plist'";
    	$qryresult = mysql_query($qry, $db_link);
    	
    	//error check
    	if(!$qryresult) die("Could not connect to the server".mysql_error($db_link));
    	
    	$row = mysql_fetch_array($qryresult, MYSQL_ASSOC);
    	
    	echo "You are editing Playlist for ".$row["date"]." Week ".$row["week"];
    	
    	//reset array pointer 
    	reset($row);
    	
    	while ($row = mysql_fetch_array($qryresult, MYSQL_ASSOC))
    	{
                   etc...
    	}
    the first line that is printed from the array result diplays the day and week result for that record, presumeably taken from record 1. Once the while loop is started it begins at record 2 NOT record 1. I have since read the the reset() function wont reset a multidimensional array, so is there a better condition i could use in my while condition rather thant mysql_fetch_array() to get it to iterate from record 1? Seems there should be as I have already assigned mysql_fetch_array() a few lines prior to the loop.

    Thanks for looking,
    Paul

  2. #2
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    Southwest US
    Posts
    203
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Instead of using reset(), use mysql_data_seek().
    This function is specifically used to move an internal result pointer.

    For your script replace:
    PHP Code:
    reset($row); 
    with:
    PHP Code:
    mysql_data_seek($qryresult0); 
    Hope this helps,
    Itshim

  3. #3
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could also just do:
    PHP Code:
    $count 1;
    while (
    $row mysql_fetch_array($qryresultMYSQL_ASSOC))
    {
        if(
    $count==1)
        {
             echo 
    "You are editing Playlist for ".$row['date']." Week ".$row['week'];
        }
        
    $count++;
        
    etc...


  4. #4
    SitePoint Wizard
    Join Date
    Aug 2004
    Location
    California
    Posts
    1,672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why reset $row when you are just going to assign to it. Maybe
    PHP Code:
    $playlist = array(); while ($row mysql_fetch_array($qryresultMYSQL_ASSOC)) { 
        
    $playlist[] = $row;

    Christopher


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •