Jump to content

Recommended Posts

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.
Link to comment
https://forums.phpfreaks.com/topic/13330-some-help-with-sql_query/
Share on other sites

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]
<?PHP
switch ($_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.
  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.