Techmate Posted July 15, 2011 Share Posted July 15, 2011 Ok I can not figure out what I am doing wrong I have been working on this for days. I wrote a script that will allow a user to create a new table in the database. After the table is created the user can upload an image to that table all is good there. Next the user clicks on the link of the table which displays all the images using pagination. Here is were my problem is I would like to convert the categories into a variable so that I can use the same pagination file to display the images in a table. Each tables in the mysql database consists of a id, name and mediumimage blob. When I add the table name in my $sql varible it is fine so for instins I add car it is fine. Now if I make it into a variable the first page shows all the pictures fine when I click on the next page I get this error. CAN SOMEONE PLEASE HELP ME HERE IS THE SCRIPT LISTED BELOW :'( If I remove the This works fine! but defeats the point of having categories but I need to substitute the whatever with a variable something like $varibleIwouldlike and that is it. $sql = "SELECT COUNT(*) FROM whatever"; This does not work I get the error Notice: Undefined index: gallerytbl in /var/www/hgg/gallery.php on line 27 SELECT COUNT(*) FROM Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in /var/www/hgg/gallery.php on line 40 Notice: SQL in /mysiteinformation on line 40 Fatal error: SQL in //mysiteinformation on line 73 <?php //connection stuff $varibleIwouldlike=$_GET['Cars']; echo "<div id=\"gallery\">"; // find out how many rows are in the table $sql = "SELECT COUNT(*) FROM $varibleIwouldlike"; $result = mysql_query($sql) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 10; // find out total pages $totalpages = ceil($numrows / $rowsperpage); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; // get the info from the db $sql = "SELECT id, image FROM $varibleIwouldlike LIMIT $offset, $rowsperpage"; $result = mysql_query($sql) or trigger_error("SQL", E_USER_ERROR); // while there are rows to be fetched... while ($list = mysql_fetch_assoc($result)) { $listidagain=$list['id']; // echo data //echo $list['id'] . " : " . $list['image'] . "<br />"; //$img= $list['image']; //echo $list['image'] . "<br />"; $lastid = mysql_insert_id(); echo "<a href=\"get.php?id=$listidagain\">" . "<img src=get.php?id=$listidagain width=100></a>" . " "; } // end while /****** build the pagination links ******/ // range of num links to show $range = 20; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo "<br>"; echo "<a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo "<a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo "<br>[<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // end if /****** end build pagination links ******/ ?> SOMEONE PLEASE HELP ME!!! Quote Link to comment https://forums.phpfreaks.com/topic/242036-need-help-pagination-please/ Share on other sites More sharing options...
Psycho Posted July 15, 2011 Share Posted July 15, 2011 Why are you using separate tables? just use one table with a separate column to specify the category. Anyway, with regard to your issue, you need to verify the value of $varibleIwouldlike. Since you are defining it from a GET variable you don't know if it is what you think it is. Echo your queries to the page and see if they are valid. Your queries are obviously failing but all you are using for the error handling is to display "SQL". Why aren't you using mysql_error() which will give you more details about the errors? trigger_error(mysql_error(), E_USER_ERROR); Quote Link to comment https://forums.phpfreaks.com/topic/242036-need-help-pagination-please/#findComment-1242975 Share on other sites More sharing options...
Techmate Posted July 15, 2011 Author Share Posted July 15, 2011 Ok I updated the code and this is what the new error shows Notice: Undefined index: gallerytbl in /mysite on line 27 SELECT COUNT(*) FROM Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in /mysite on line 40 Fatal error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 in /mysite on line 40 Quote Link to comment https://forums.phpfreaks.com/topic/242036-need-help-pagination-please/#findComment-1242980 Share on other sites More sharing options...
TeNDoLLA Posted July 15, 2011 Share Posted July 15, 2011 So there is error in your sql query still. Echo the queries and see if it is valid SQL-syntax or even paste the echoed queries here, just like mjdamato said two posts ago. Quote Link to comment https://forums.phpfreaks.com/topic/242036-need-help-pagination-please/#findComment-1242999 Share on other sites More sharing options...
Techmate Posted July 15, 2011 Author Share Posted July 15, 2011 Can you post what you would like me to post? Sorry I am not sure what you would like me to do. Quote Link to comment https://forums.phpfreaks.com/topic/242036-need-help-pagination-please/#findComment-1243002 Share on other sites More sharing options...
TeNDoLLA Posted July 15, 2011 Share Posted July 15, 2011 echo $sql; and post results here... Quote Link to comment https://forums.phpfreaks.com/topic/242036-need-help-pagination-please/#findComment-1243003 Share on other sites More sharing options...
Techmate Posted July 15, 2011 Author Share Posted July 15, 2011 Yes it does say I have an error in SQL-syntax. I don't know what it is. that is all that echos. It should read SELECT COUNT(*) FROM whatever SELECT COUNT(*) FROM Quote Link to comment https://forums.phpfreaks.com/topic/242036-need-help-pagination-please/#findComment-1243011 Share on other sites More sharing options...
Techmate Posted July 15, 2011 Author Share Posted July 15, 2011 Techmate link=topic=338738.msg1596389#msg1596389 date=1310722864] Yes it does say I have an error in SQL-syntax. I don't know what it is. This is all that echos. It should read SELECT COUNT(*) FROM whatever SELECT COUNT(*) FROM Quote Link to comment https://forums.phpfreaks.com/topic/242036-need-help-pagination-please/#findComment-1243013 Share on other sites More sharing options...
TeNDoLLA Posted July 15, 2011 Share Posted July 15, 2011 So apparently this variable $varibleIwouldlike=$_GET['Cars']; is not ever set since you use it in your SQL query as the table name. Do a var_dump($_GET['Cars']) befopre assigning the variable to see what it contains (prolly null). Next question is where do you get this $_GET['Cars'] and how? Or are trying to, apparently its not getting it. Quote Link to comment https://forums.phpfreaks.com/topic/242036-need-help-pagination-please/#findComment-1243016 Share on other sites More sharing options...
Techmate Posted July 15, 2011 Author Share Posted July 15, 2011 Can you type out the string you would like me to implement? Also, Cars is just one of the tables that is located in the database it contains only an id auto incremented, name, image. Quote Link to comment https://forums.phpfreaks.com/topic/242036-need-help-pagination-please/#findComment-1243020 Share on other sites More sharing options...
TeNDoLLA Posted July 15, 2011 Share Posted July 15, 2011 $_GET['Cars'] means you will have to have a link, and when that link is clicked you will get the GET variable from it. Say you wanted to get the SQL table name for some reason from a link you should do something like this: <?php // If link was clicked get data from db. if (isset($_GET['table']) && $_GET['table'] === 'cars') { $tableName = $_GET['table']; $sql = "SELECT * FROM $tableName"; // Gettin all stuff from db table called 'cars'. // run query and process data here.. } ?> <html> <head><title></title></head> <body> <a href="somepage.php?table=cars">Get info from cars table</a> </body> </html> Now this is going offtopic and got nothing to do with paging anymore. You should read some basic tutorials and learn from them to get the basic ideas and technics. Quote Link to comment https://forums.phpfreaks.com/topic/242036-need-help-pagination-please/#findComment-1243024 Share on other sites More sharing options...
Techmate Posted July 15, 2011 Author Share Posted July 15, 2011 I have a link coming from $_POST. I don't believe we are being clear. I just need someone to read the code that understands it and can help me. If it is to complicated for you I understand...but thank you! Someone else please help... Quote Link to comment https://forums.phpfreaks.com/topic/242036-need-help-pagination-please/#findComment-1243026 Share on other sites More sharing options...
TeNDoLLA Posted July 15, 2011 Share Posted July 15, 2011 It is not complicated for me, I understand your code fully. But why are you using $_GET variables in there if you are getting the data from $_POST? And second of all, you can't get $_POST variable from a link unless you are using AJAX and I am pretty sure you are not. Quote Link to comment https://forums.phpfreaks.com/topic/242036-need-help-pagination-please/#findComment-1243043 Share on other sites More sharing options...
Psycho Posted July 15, 2011 Share Posted July 15, 2011 I have a link coming from $_POST. I don't believe we are being clear. I just need someone to read the code that understands it and can help me. If it is to complicated for you I understand...but thank you! Someone else please help... Techmate, there is no need to get an attitude. The problem is perfectly clear and you seem to be the one who does not understand. You are setting the $varibleIwouldlike variable using $varibleIwouldlike=$_GET['Cars']; And the query you are echoing to the page clearly shows that the $varibleIwouldlike variable is empty and/or a null string. So, it is obvious that $_GET['Cars'] has no value. That is the root of your problem. I even stated in my first post ...you need to verify the value of $varibleIwouldlike But even with the answer staring you in the face you are at a loss. And, instead of taking TeNDoLLA's advice you decide to try and belittle him. As TeNDoLLA was trying to state you don't have $_GET values sent through a POST, but it is possible to have GET values in addition to POST values be putting the value in the URL of the action attribute of the form. But, to be honest I haven't a clue what you are doing before this page is called. So, I have to agree with him that you need to step back and understand what you are doing. Maybe you are an exceptional programmer and have just got confused after countless hours of troubleshooting. But, based upon the fact there are numerous flaws in your code and logic I'm guessing you are still learning and there's nothing wrong with that. We all come here to help and be helped. Quote Link to comment https://forums.phpfreaks.com/topic/242036-need-help-pagination-please/#findComment-1243086 Share on other sites More sharing options...
Techmate Posted July 15, 2011 Author Share Posted July 15, 2011 Didn't mean to sound brash, I clearly understand what you are saying but you are right you are not clear what I am saying. Here is the link http://testsiteherethanks.redirectme.net this should help. I know that store is emply it will be filled up as soon as we can fix this problem so lets click on Cars. I know that there are no cars in this category I just uploaded random pictures to show you what is going on there click on page 2 and you will see what is perplexing me? Quote Link to comment https://forums.phpfreaks.com/topic/242036-need-help-pagination-please/#findComment-1243252 Share on other sites More sharing options...
Psycho Posted July 15, 2011 Share Posted July 15, 2011 That link is not valid. It looks like it is a dynamic DNS, so I assume it is pointing to your internal environment. It may not be accepting external requests. Anyway, we have already identified the problem with that script above. The variable $_GET['Cars'] does not exist (or is empty). You need to look at how you are getting to that page above. To have a value in $_GET['Cars'] you would have to be requesting a page using a link such as http://www.mysite.com?Cars=foo Quote Link to comment https://forums.phpfreaks.com/topic/242036-need-help-pagination-please/#findComment-1243253 Share on other sites More sharing options...
Techmate Posted July 15, 2011 Author Share Posted July 15, 2011 Didn't mean to sound brash, I clearly understand what you are saying but you are right you are not clear what I am saying. Here is the link http://testsiteherethanks.redirectme.net this should help. I know that store is emply it will be filled up as soon as we can fix this problem so lets click on Cars. I know that there are no cars in this category I just uploaded random pictures to show you what is going on there click on page 2 and you will see what is perplexing me? Here is the script that sends the information to $_GET <?php session_start(); include ("mysqlconnect.php"); confff("Gallery"); error(); $sql = "SHOW TABLES FROM Gallery"; $result = mysql_query($sql); while ($row = mysql_fetch_row($result)) { $res []=$row; $tablelist="{$row[0]}"; echo "<a href=\"index.php?tble=$tablelist\"> $tablelist </a>"; //$_SESSION = [$tablelist]; echo "<br>"; } //mysql_free_result($result); ?> [/code] Here is the script that receives the script listed above. <?php session_start(); //connection information include ("mysqlconnect.php"); confff("Gallery"); error(); //-------------------- $sql = "SHOW TABLES FROM Gallery"; $result = mysql_query($sql); while ($row = mysql_fetch_row($result)) { $res []=$row; $tablelist="{$row[0]}"; echo "<a href=\"gallery.php?tble=$tablelist\"> $tablelist </a>"; //$_SESSION = [$tablelist]; echo "<br>"; } //mysql_free_result($result); ?> Completed Code Quote Link to comment https://forums.phpfreaks.com/topic/242036-need-help-pagination-please/#findComment-1243259 Share on other sites More sharing options...
Psycho Posted July 15, 2011 Share Posted July 15, 2011 Um, you posted the same script twice. Anyway, the problem is pretty obvious. Again, you need to step back and actually READ what is being posted. In my last post I stated you needed to have the following on your query string: "Cars=foo" Now, look at the code you just posted and the links you are creating. You are using "tble=$tablelist" "Cars" != "tble" You are calling the wrong GET variable. Quote Link to comment https://forums.phpfreaks.com/topic/242036-need-help-pagination-please/#findComment-1243272 Share on other sites More sharing options...
Techmate Posted July 16, 2011 Author Share Posted July 16, 2011 Ok here is the link http://68.108.191.206:8000 again this should help you understand what I need. So the user will create a dynamic category right named Cars, boats, what ever then the category (it is not a link I create that will be there for ever like cars=foo...IT HAS TO BE a variable. It could be deleted and another link could go in its place renamed etc.)is listed now when someone clicks on that link it will take them to that gallery. Cars=foo will not work for me I do not believe please try to understand what I am asking of you I DO UNDERSTAND your method but it is not the method I need... please try to understand what I need. If you have to reread it thank you thank you again....Then could you please revise what I wrote wrong Please write out your complete code if you understand my endeavors. Thank you so much! Quote Link to comment https://forums.phpfreaks.com/topic/242036-need-help-pagination-please/#findComment-1243337 Share on other sites More sharing options...
Psycho Posted July 16, 2011 Share Posted July 16, 2011 ... this should help you understand what I need. Then could you please revise what I wrote wrong... Um, I know what you need. You need to READ and UNDERSTAND what has been conveyed to you in this thread and then LOOK at your code to see what is wrong. The answer has been staring you in the face. I pointed you in the right direction with the very first respons you need to verify the value of $varibleIwouldlike. But, apparently that was too much work for you. So, instead this thread has gone on way too long and wasted my time and yours. These are what your links look like that creates those links <a href="gallery.php?cars=Cars"> Cars </a><br><a href="gallery.php?cars=store"> store </a><br> This is how you are defining your table name from the GET data $varibleIwouldlike=$_GET['Cars']; "Cars" does not equal "cars" Quote Link to comment https://forums.phpfreaks.com/topic/242036-need-help-pagination-please/#findComment-1243342 Share on other sites More sharing options...
phpjay Posted July 16, 2011 Share Posted July 16, 2011 try this //check if the starting row variable was passed in the URL or not if (!isset($_GET['record_display']) or !is_numeric($_GET['record_display'])) { //we give the value of the starting row to 0 because nothing was found in URL $record_display = 0; //otherwise we take the value from the URL } else { $record_display = (int)$_GET['record_display']; } // your sql code here.. <?PHP $prev = $record_display - 3; //only print a "Previous" link if a "Next" was clicked if ($prev >= 0) echo '<a href="'.$_SERVER['PHP_SELF'].'?record_display='.$prev.'"><font size="2px">Prev</font></a>'; ?> <?PHP //now this is the link.. echo '<a href="'.$_SERVER['PHP_SELF'].'?record_display='.($record_display+3).'"><font size="2px">Next</font></a>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/242036-need-help-pagination-please/#findComment-1243344 Share on other sites More sharing options...
Techmate Posted July 16, 2011 Author Share Posted July 16, 2011 Thank you so much phpjay I tried it but still get errors. mjdamato I know that works. But that is not what I need like I said in my very first post. The tables will be listed on a page like Cars, store, etc. They will be links that will take you to each seporate gallery. I will not create them my self users can create what ever table they want and photos can be uploaded. That is why I need something like Cars=$variable. Can someone write a script pagination for what i am looking for if my code is to robust. Thank you so much. Quote Link to comment https://forums.phpfreaks.com/topic/242036-need-help-pagination-please/#findComment-1243345 Share on other sites More sharing options...
Techmate Posted July 16, 2011 Author Share Posted July 16, 2011 I tried it phpjay it is not what I am looking for....I don't know how to explain it any clearer. The users can create whatever table that includes an id, name, image meduimblob. Think of how this forum works there is a topic (categories for me) You click on the topic in the topic is the message (photos for me). Now someone can easily create a new topic and post what ever I need the something but for a photo gallery. Know I wrote the entire code it is great now I just need it to work with a variable that will recognize when a user send a link to it and find the table in the database... What I am getting and had created ed is a plain massive gallery that contains everything not categories please please please try and understand anyone I am not trying to be rude ANOTHER GOOD EXAMPLE: Car <----is a link that is created by a user not me the users need to be able to create another category in the database that contains pictures that are paginations. Store <----is a link that is created by a user not me the users need to be able to create another category in the database that contains pictures that are paginations. Boat example name <---- is a link that is created by a user not me the users need to be able to create another category in the database that contains pictures that are paginations. Duck is a link that is created by a user not me the users need to be able to create another category in the database that contains pictures that are paginations etc. Before replying please ask your self this can a user create a Category and not have to have access to the php file and now code to show the gallery CLICK HERE TO SEE WHAT I NEED http://68.108.191.206:8000/ Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/242036-need-help-pagination-please/#findComment-1243356 Share on other sites More sharing options...
TeNDoLLA Posted July 16, 2011 Share Posted July 16, 2011 Not sure if I am following you anymore but if I am, I dont know if I can make more clear example than this. Say you have data in database like below table : user_created_galleries_in_db id | gallery_name --------------------------------- 1 | Cars 2 | Store 3 | Something table : images id | image | gallery_id (references to user_created_galleries_in_db(id)) ----------------------------------------------------------------------------- 1 | car1.jpg | 1 2 | car2.jpg | 1 3 | car3.jpg | 1 Then this is how you show images from gallery // Sql for creating the links to the page $sql = "SELECT id, gallery_name FROM table user_created_links_in_db"; $result = mysql_query($sql); // Generate the liks from user created galleries from db while($row = mysql_fetch_assoc($result)) { echo '<a href="gallery_id='. $row['id'] .'">'. $row['gallery_name'] .'</a></br>'; } // Now if user clicks gallery link, show the data related to that gallery if (isset($_GET['gallery']) && intval($_GET['callery_id']) > 0) { $galleryId = intval($_GET['gallery_id']); $sql = "SELECT image FROM images WHERE gallery_id = $galleryId"; $result = mysql_query($sql); // Show images in clicked glalery while($row = mysql_fetch_assoc($result)) { // Show image data } } Quote Link to comment https://forums.phpfreaks.com/topic/242036-need-help-pagination-please/#findComment-1243412 Share on other sites More sharing options...
Techmate Posted July 16, 2011 Author Share Posted July 16, 2011 Thank you. I will try it and let you know if this helps... Quote Link to comment https://forums.phpfreaks.com/topic/242036-need-help-pagination-please/#findComment-1243495 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.