foreverhex Posted June 30, 2006 Share Posted June 30, 2006 Ive been using php for a while now, but I am still new at MySQL. I had a question about how to retrieve data from a sql table. i believe I use the sql_query to do it but Im not sure. Below is my example.[list][*]-ppl submit art and info with it-it stored to Mysql under the table "art" with a row called medium (photo, draw, cg)-there is a page that pulls up this art called "art.php"-if you goto the photography page (art.php?medium=photo) it shows only photos-if you go to drawing ect ect.-how do i make it grab only the art i request instead of the entire art table?-also how do I go about making a flexible html table to desplay this info?-is it hard to do pagination with all this?[/list]Thanks for the help, someone always comes through and hits the nail on the head. Quote Link to comment https://forums.phpfreaks.com/topic/13330-some-help-with-sql_query/ Share on other sites More sharing options...
gijew Posted June 30, 2006 Share Posted June 30, 2006 I may be able to answer a few of those questions...If each row has a unique number tied to it in MySQL called a primary key, you can use that to easily and safely display an individual row.Example: <a href="art.php?photo=medium&photoID=1">Click for medium photo</a>You can write a simple conditional or switch() to get it to display what you're looking for (I prefer switch).This is just a simple guestimation of what to do.[code]<?PHPswitch ($_GET['Photo') { default: echo 'whatever it is you want to be displayed by default.'; break; case 'medium'; // If the user has opted to select an individual photo, store the WHERE clause in a variable so we don't have to double up on our work. if ($_GET['photoID']) { $PhotoConditional = 'WHERE photo_id = $_GET[photoID]'; } $SQL_Photo = MySQL_Query("SELECT photo FROM art $PhotoConditional"); while ($r = MySQL_Fetch_Array($SQL_Photo)) { echo $r['photo'].'<br />'; } break;)?>[/code]The above switch() should in theory display either all data or a single photo. If you want all, just don't include the photoID in the URL.Pagination is an entirely and painful subject. I recommend going into the tutorials on this website and read the one there to get a better understanding of what to do. Quote Link to comment https://forums.phpfreaks.com/topic/13330-some-help-with-sql_query/#findComment-51416 Share on other sites More sharing options...
Barand Posted July 1, 2006 Share Posted July 1, 2006 art table-----------art_id (PK)artist_idimage_pathmedium (= 'photo', 'draw' etc)If user selects photo pageSELECT * FROM art WHERE medium = 'photo' Quote Link to comment https://forums.phpfreaks.com/topic/13330-some-help-with-sql_query/#findComment-51477 Share on other sites More sharing options...
fenway Posted July 3, 2006 Share Posted July 3, 2006 The pagination is really the hardest part of all this... you have run some fancy SQL to get the entire result set count efficiently. Quote Link to comment https://forums.phpfreaks.com/topic/13330-some-help-with-sql_query/#findComment-52320 Share on other sites More sharing options...
foreverhex Posted July 11, 2006 Author Share Posted July 11, 2006 Thx Barand for helping me on my table layout and gijew for the sample code. I tried it our and its seems to be working pretty good. Ill do some altering and send a link so that you guys can check it out when its done. THX! Quote Link to comment https://forums.phpfreaks.com/topic/13330-some-help-with-sql_query/#findComment-56175 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.