Jump to content

offset error


divinedesigns1
 Share

Recommended Posts

how can i fixed this offset error? i put the $i variable since $data[] is an array so its like $data[$i]['album_id'] but im getting an offset error on that specific line updated code

<?php// Retrieve album information (photo count, description, etc.) from database$sql = "SELECT album.album_id, album.album_name, album.album_desc, album.album_cover, COUNT(photo.photo_id) as imagesFROM album LEFT JOIN photo ON album.album_id = photo.album_idGROUP BY album.album_name, album.album_descORDER BY album.album_id ASC";$result = mysql_query($sql) or die("Error retrieving records from the database: " . mysql_error());$i = 0; // Row counterwhile( $row = mysql_fetch_assoc($result)){$data[] = $row;}$count = (ceil(count($data) / IMAGE_DISPLAY ));for($i = (int)0; $i < $count * IMAGE_DISPLAY; $i++){if(($i % IMAGE_DISPLAY) == 0 && ($i != 0)){echo("</tr>\n<tr>");}if($data[$i]['album_cover']){echo("<td valign=\"top\" width=\"" . floor(100 / IMAGE_DISPLAY) . "%\">\n");echo("<p><a href=\"view_album.php?album_id=" . $data[$i]['album_id'] . "\">" . $data[$i]['album_name'] . " (" . $data[$i]['images'] . ")</a></p><a href=\"view_album.php?album_id=" . $data[$i]['album_id'] . "\"><img src=\"" . $data[$i]['album_cover'] . "\" title=\"" . $data[$i]['album_desc'] . "\" align=\"middle\"></a>");echo("<br /><p>" . $data[$i]['album_desc'] . "</p>\n</td>\n");}else{echo("<td valign=\"top\" width=\"" . floor(100 / IMAGE_DISPLAY) . "%\"> ");echo("</td>\n");}}?>

and yes i will be converting it to mysqli after i fixed the errorsthe error start here if($data[$i]['album_cover']){ so can anyone explain, and show me how to fix this so ill know how to next time

Link to comment
Share on other sites

did you try var_dump() $data inside the 'for' loop?

Link to comment
Share on other sites

did you try var_dump() $data inside the 'for' loop?
yup it became back boolen true
Link to comment
Share on other sites

Do you Mean Like this.

Do you mean.<?PHPrequire("connect.php");define("IMAGE_DISPLAY",4);define("cover_width",300);//include('function.php');$sql = "SELECT album.album_id, album.album_name, album.album_desc, album.album_cover, COUNT(photo.photo_id) as imagesFROM album LEFT JOIN photo ON album.album_id = photo.album_idGROUP BY album.album_name, album.album_descORDER BY album.album_id ASC";$result = mysql_query($sql) or die("Error retrieving records from the database: " . mysql_error());$i = 0; // Row counterecho "<table>";while( $row = mysql_fetch_assoc($result)){$album_cover='';//$data[] = $row;	 if(($i % IMAGE_DISPLAY) == 0 && ($i != 0))    {	    echo("</tr>\n<tr>");    }    if($row['album_cover'])    {    $album_cover='upload/'.$row['album_cover'];    echo("<td valign=\"top\" width=\"" . floor(100 / IMAGE_DISPLAY) . "%\">\n");    echo("<p><a href=\"view_album.php?album_id=" . $row['album_id'] . "\">" . $row['album_name'] . " (" . $row['images'] . ")</a></p><a href=\"view_album.php?album_id=" . $row['album_id'] . "\"><img src=\"" . $album_cover . "\" title=\"" . $row['album_desc'] . "\" align=\"middle\" width=\"".cover_width."\"></a>");    echo("<br /><p>" . $row['album_desc'] . "</p>\n</td>\n");    }    else    {    echo("<td valign=\"top\" width=\"" . floor(100 / IMAGE_DISPLAY) . "%\"> ");    echo("</td>\n");    }   $i++;   /*echo $row['album_id'];echo $row['album_name'];echo $row['album_desc'];echo $row['images'];echo '<br/>';*/}echo "</table>";?>

Link to comment
Share on other sites

yes, i kinda figure that it wasnt an array, how would you make it as an array anyway? and ill try your way, sorry for the late reply

Link to comment
Share on other sites

<?PHPrequire("connect.php");define("IMAGE_DISPLAY",3);define("cover_width",300);define("upload_folder","upload/");//include('function.php');$sql = "SELECT album.album_id, album.album_name, album.album_desc, album.album_cover, COUNT(photo.photo_id) as imagesFROM album LEFT JOIN photo ON album.album_id = photo.album_idGROUP BY album.album_name, album.album_descORDER BY album.album_id ASC";$result = mysql_query($sql) or die("Error retrieving records from the database: " . mysql_error());$data = array();while( $row = mysql_fetch_assoc($result)){  $data[]  = $row;}    echo "<table border=\"1\">"; foreach ($data as $i => $value)    {    $album_cover='';    //echo $data[$i]['album_name'];    if(($i % IMAGE_DISPLAY) == 0 && ($i != 0))    {	    echo("</tr>\n<tr>");    }    if($data[$i]['album_cover'])    {	    echo("<td valign=\"top\" width=\"" . floor(100 / IMAGE_DISPLAY) . "%\">\n");	    echo("<p><a href=\"view_album.php?album_id=" . $data[$i]['album_id'] . "\">" . $data[$i]['album_name'] . " (" . $data[$i]['images'] . ")</a></p><a href=\"view_album.php?album_id=" . $data[$i]['album_id'] . "\"><img src=\"" . upload_folder.$data[$i]['album_cover'] . "\" title=\"" . $data[$i]['album_desc'] . "\" align=\"middle\" width=\"".cover_width."\"></a>");	    echo("<br /><p>" . $data[$i]['album_desc'] . "</p>\n</td>\n");    }    else    {	    echo("<td valign=\"top\" width=\"" . floor(100 / IMAGE_DISPLAY) . "%\"> ");	    echo("</td>\n");    }     }echo "</table>";?>

Edited by kanchatchai
Link to comment
Share on other sites

Initialize it as an empty array before trying to add the rows to it.
ok thanks ill do that. kanchatchai thanks, but your not suppose to do the whole thing for me
Link to comment
Share on other sites

they need to have a booty shaking icon here, so when i figure out something i can use it. anyway i got it to display, what i did was remove all of those extra code and just echo out the information and it worked perfectly fine

Link to comment
Share on other sites

Do you Mean Like this.
Do you mean.<?PHPrequire("connect.php");define("IMAGE_DISPLAY",4);define("cover_width",300);//include('function.php');$sql = "SELECT album.album_id, album.album_name, album.album_desc, album.album_cover, COUNT(photo.photo_id) as imagesFROM album LEFT JOIN photo ON album.album_id = photo.album_idGROUP BY album.album_name, album.album_descORDER BY album.album_id ASC";$result = mysql_query($sql) or die("Error retrieving records from the database: " . mysql_error());$i = 0; // Row counterecho "<table>";while( $row = mysql_fetch_assoc($result)){$album_cover='';//$data[] = $row;	 if(($i % IMAGE_DISPLAY) == 0 && ($i != 0))	{		echo("</tr>\n<tr>");	}	if($row['album_cover'])	{	$album_cover='upload/'.$row['album_cover'];	echo("<td valign=\"top\" width=\"" . floor(100 / IMAGE_DISPLAY) . "%\">\n");	echo("<p><a href=\"view_album.php?album_id=" . $row['album_id'] . "\">" . $row['album_name'] . " (" . $row['images'] . ")</a></p><a href=\"view_album.php?album_id=" . $row['album_id'] . "\"><img src=\"" . $album_cover . "\" title=\"" . $row['album_desc'] . "\" align=\"middle\" width=\"".cover_width."\"></a>");	echo("<br /><p>" . $row['album_desc'] . "</p>\n</td>\n");	}	else	{	echo("<td valign=\"top\" width=\"" . floor(100 / IMAGE_DISPLAY) . "%\"> ");	echo("</td>\n");	}  $i++;  /*echo $row['album_id'];echo $row['album_name'];echo $row['album_desc'];echo $row['images'];echo '<br/>';*/}echo "</table>";  ?>

sorry i didnt see this post
Link to comment
Share on other sites

ok so i got it displaying but im not getting it to display by four, ahh back to the drawing board hehehehehe

Link to comment
Share on other sites

this is what i do, for it to display the albums

<?php// Retrieve album information (photo count, description, etc.) from database$sql = "SELECT album.album_id, album.album_name, album.album_desc, album.album_cover, COUNT(photo.photo_id) as imagesFROM album LEFT JOIN photo ON album.album_id = photo.album_idGROUP BY album.album_name, album.album_descORDER BY album.album_id ASC";$result = mysql_query($sql) or die("Error retrieving records from the database: " . mysql_error());while($row = mysql_fetch_assoc($result)){echo("<td valign=\"top\" width=\"" . floor(100 / IMAGE_DISPLAY) . "%\">\n");echo("<p><a href=\"view_photo.php?album_id=" . $row['album_id'] . "\">" . $row['album_name'] . " (" . $row['images'] . ")</a></p><a href=\"view_photo.php?album_id=" . $row['album_id'] . "\"><img src=\"" . $row['album_cover'] . "\" title=\"" . $row['album_desc'] . "\" align=\"middle\"></a>");echo("<br /><p>" . $row['album_desc'] . "</p>\n</td>\n");}?>

its the only way that it is displaying, if i add the rest of codes i have on a notepad it just give me the heading and the menu below which doesnt work for me

Edited by DDs1
Link to comment
Share on other sites

Wait, are you trying to paginate SQL data? There's a much easier way than what you're doing: Use LIMIT (see SELECT in the MySQL manual for details).The first number in LIMIT is the starting point, which is easily calculated by multiplying the records per page with the page number (-1, since the first page will need to have 0 as this first number). The second number is the number of entries past the offset, which is basically equal to your records per page.Not only is this more efficient, it's also easier to deal with, as once you take the result set, you just output it in the same fashion as you'd output it if there was no pagination.

Link to comment
Share on other sites

Wait, are you trying to paginate SQL data? There's a much easier way than what you're doing: Use LIMIT (see SELECT in the MySQL manual for details). The first number in LIMIT is the starting point, which is easily calculated by multiplying the records per page with the page number (-1, since the first page will need to have 0 as this first number). The second number is the number of entries past the offset, which is basically equal to your records per page. Not only is this more efficient, it's also easier to deal with, as once you take the result set, you just output it in the same fashion as you'd output it if there was no pagination.
ok one more question how can i made a index key, yeah you have id as the primary key then you have undo_id as the index key, how do i make that key have a number set automatically without putting the number in manually???
Link to comment
Share on other sites

i am not sure what you mean by undo_key, if you want to increment the value of a colum on each insert you can set it s auto_increment

Link to comment
Share on other sites

DDS1 Do you Insert Admin Code. and pagination

<?PHPsession_start();if (!isset($_SESSION["uid"]))echo "<a href=\"login.php\">Login <img src=\"icon/security.png\" alt=\"[Login]\" title=\"[Login]\" border=\"0\"></a>";else{echo "<a href=\"logout.php\">Logout <img src=\"icon/logout.png\" title=\"Logout\" alt=\"[Logout]\" border=\"0\"></a>";echo "<a href=\"album_insert_form.php\">Add <img src=\"icon/add.png\" title=\"Add Ablum\" alt=\"[Add Ablum]\" border=\"0\"></a>";}require("connect.php");/*---------------Begin pagination Check-----------------*/define("per_page",1);$total_pages = mysql_fetch_array(mysql_query("SELECT COUNT(*) as num FROM album"));$total_pages = $total_pages["num"];        $stages = 3;        if (isset($_GET['page']))        {                $page = mysql_escape_string($_GET['page']);                                    if($page){                                                                                            $start = ($page - 1) * per_page;                                                         }else{                    $start = 0;                                                                                    }            }        else        {        $page=1;        $start = 0;            }/*---------------End Begin pagination Check-----------------*/        //define("IMAGE_DISPLAY",2);//define("cover_width",300);//include('function.php');$sql = "SELECT album.album_id, album.album_name, album.album_desc, album.album_cover, COUNT(photo.photo_id) as imagesFROM album LEFT JOIN photo ON album.album_id = photo.album_idGROUP BY album.album_name, album.album_descORDER BY album.album_id ASC LIMIT $start ,".per_page;        $result = mysql_query($sql) or die("Error retrieving records from the database: " . mysql_error());$i = 0; // Row counterecho "<table>";while( $row = mysql_fetch_assoc($result)){$album_cover=''; //$data[] = $row;     if(($i % IMAGE_DISPLAY) == 0 && ($i != 0))    {        echo("</tr>\n<tr>");    }    if($row['album_cover'])    {    $album_cover='upload/'.$row['album_cover'];    echo("<td valign=\"top\" width=\"" . floor(100 / IMAGE_DISPLAY) . "%\">\n");    echo("<p><a href=\"view_album.php?album_id=" . $row['album_id'] . "\">" . $row['album_name'] . " (" . $row['images'] . ")</a></p><a href=\"view_album.php?album_id=" . $row['album_id'] . "\"><img src=\"" . $album_cover . "\" alc=\"" . $album_cover . "\"title=\"" . $row['album_desc'] . "\" align=\"middle\" width=\"".cover_width."\"></a>");        if (isset($_SESSION["uid"]))    {        //or you can add code in view_album.php        echo "<br /><a href=\"add_image.php?album_id=".$row['album_id']."\"><img src=\"icon/add.png\" alt=\"add\" border=\"0\"></a>";            echo "<a href=\"album_update_form.php?album_id=".$row['album_id']."\"><img src=\"icon/edit.png\" alt=\"[edit]\" border=\"0\"></a> ";    if ($row['images']==0)//if no have image you can delete album        echo "<a href=\"?action=delete&album_id=".$row['album_id']."\"><img src=\"icon/del.png\" alt=\"[del]\" border=\"0\"></a>";        }        echo("<br /><p>" . $row['album_desc'] . "</p>\n</td>\n");    }    else    {    echo("<td valign=\"top\" width=\"" . floor(100 / IMAGE_DISPLAY) . "%\"> ");    echo("</td>\n");    }    $i++;    }echo "</table>";  Function pagination($total_pages,$page,$start,$stages,$more_url){        // Initial page num setup        if ($page == 0){$page = 1;}        $prev = $page - 1;                                                            $next = $page + 1;                                                                                $lastpage = ceil($total_pages/per_page);                                    $LastPagem1 = $lastpage - 1;                                                                $paginate = '';                                                                    if($lastpage > 1)                                                            {                $paginate .= "<div class='paginate'>";                // Previous            if ($page > 1){                                                                $paginate.= "<a href='?page=1$more_url'>«</a>";                    // |< First                $paginate.= "<a href='?page=$prev$more_url'>‹ </a>";            //<Back            }else{                $paginate.= "<span class='disabled'>«</span>";                // |< First                $paginate.= "<span class='disabled'>‹ </span>";                //<Back                }                                        // Pages                if ($lastpage < 7 + ($stages * 2))                {                    for ($counter = 1; $counter <= $lastpage; $counter++)                    {                    if ($counter == $page){                        $paginate.= "<span class='current'>$counter</span>";                    }else{                        $paginate.= "<a href='?page=$counter$more_url'>$counter</a>";}                                    }            }            elseif($lastpage > 5 + ($stages * 2))    // Enough pages to hide a few?            {                // Beginning only hide later pages                if($page < 1 + ($stages * 2))                        {                        for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)                        {                            if ($counter == $page){                                $paginate.= "<span class='current'>$counter</span>";                            }else{                                $paginate.= "<a href='?page=$counter$more_url'>$counter</a>";}                                            }                        $paginate.= "...";                        $paginate.= "<a href='?page=$LastPagem1$more_url'>$LastPagem1</a>";                        $paginate.= "<a href='?page=$lastpage$more_url'>$lastpage</a>";                        }                // Middle hide some front and some back                elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))                {                    $paginate.= "<a href='?page=1$more_url'>1</a>";                    $paginate.= "<a href='?page=2$more_url'>2</a>";                    $paginate.= "...";                    for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)                    {                        if ($counter == $page){                            $paginate.= "<span class='current'>$counter</span>";                        }else{                            $paginate.= "<a href='?page=$counter$more_url'>$counter</a>";}                                        }                    $paginate.= "...";                    $paginate.= "<a href='?page=$LastPagem1$more_url'>$LastPagem1</a>";                    $paginate.= "<a href='?page=$lastpage$more_url'>$lastpage</a>";                        }                // End only hide early pages                else                {                    $paginate.= "<a href='?page=1$more_url'>1</a>";                    $paginate.= "<a href='?page=2$more_url'>2</a>";                    $paginate.= "...";                    for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)                    {                        if ($counter == $page){                            $paginate.= "<span class='current'>$counter</span>";                        }else{                            $paginate.= "<a href='?page=$counter$more_url'>$counter</a>";}                                        }                }            }                                            // Next            if ($page < $counter - 1){                $paginate.= "<a href='?page=$next$more_url'> ›</a>"; //Next >                //$paginate.= "<a href='?page=".($counter-1)."$more_url'>»</a>"; //Last >|                $paginate.= "<a href='?page=$lastpage$more_url'>»</a>"; //Last >|            }else{                $paginate.= "<span class='disabled'> ›</span>";  //Next >                $paginate.= "<span class='disabled'>»</span>"; //Last >|                }            $paginate.= "</div>";                    }     return $total_pages.' Results '.$paginate;  }   /*---------------pagination-----------------*/        echo pagination($total_pages,$page,$start,$stages,"&orderby="); ?>

Edited by kanchatchai
Link to comment
Share on other sites

i am not sure what you mean by undo_key, if you want to increment the value of a colum on each insert you can set it s auto_increment
undo_key was just an example i was using
Link to comment
Share on other sites

ooo lawd i think i need to re-explain what im trying to do. ok lets goooo!!!! what im trying to do is make a photo album which displays the album name and once the album is clicked it displays the photos inside of that album. also those albums should be display inline (horizontal), and it should display albums W X Y Z, etc for the pagination, the code for that is there already its just sitting waiting for this script to be working like it should. also the pictures in the albums should only be the photos that is assisted to that album ( thats where the undo_key example i give earlier comes into play ). now what i was asking earlier was how can i make the undo_key which is an index to have the same number as the id. for example, if i have an album in the db name smith, and smith have an id of 600, and the photos that is for album smith of id 600. but in the db the images/photo/clips have a index id of undo_key which is a int also, but its not an auto increment, how can i make the undo_key have that same exact number as album smith id 600? thats what i was asking. i think i explainned it as well as i can, if you still dont get what im saying ill fix an example and show you guys

Link to comment
Share on other sites

<a href=\"view_album.php?album_id=" . $row['album_id'] That mean...

<?PHP$sql = "SELECT * from photo";if (isset($_GET['album_id']))//<----------$_GET['album_id']{ $result1 = mysql_query("select * from album where album_id='".$_GET['album_id']."'") or die("Error retrieving records from the database: " . mysql_error()); $sql = $sql." ".$_GET['album_id'];  while( $row = mysql_fetch_assoc($result1)) { /* Show Album Description */ /* Show Admin part To Insert more Photo*/ }}/* If want pagination see my last code copy my function to function.php and include it*/$result2 = mysql_query($sql) or die("Error retrieving records from the database: " . mysql_error());$i = 0; // Row counterecho "<table>";while( $row = mysql_fetch_assoc($result2)){/* Do It Like First Code *//* Show Photo *//* Show Admin part To Update/Delete Photo*/}?>

Link to comment
Share on other sites

but in the db the images/photo/clips have a index id of undo_key which is a int also, but its not an auto increment, how can i make the undo_key have that same exact number as album smith id 600?
You have to do it manually. you need to know which user id you have to insert and then you will insert that id in album table.you can use session to insert user id. you will set the id when user succefully logged in.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...