Jump to content

[SOLVED] PHP MYSQL pulling data and opening new file - Trying to Understand Concept


ofmyst

Recommended Posts

I asked previously but the problem was not resolved, mainly I think because I could not understand the concept well enough to follow the logic.  Here is what I am trying to do.  Perhaps if I can understand the logic of the commands I will be able to get it right.

 

I have a mysql database (called paintings) and a table within (called tinkers) with an inventory of paintings.  In the fileds are ID (1 - 8), [id] the address for the JPG [image tn], the link to the file that give more information and a larger version of the image [link], the address for the larger image [image], the title [title], medium[medium] and size .

 

The file that calls up the database to show the array of paintings is tinker.php.  This page works fine. 

 

If the viewer would like to see an enlargement with further information the link is called view.php.  This is where my problem comes.  I cannot get the link to pull the information for that particular painting into the new page.  I believe the link would be view.php?id=1, etc.  but do I put the link in as <a href="view.php"> and the rest pulls itself, or do I put it in as <a href="view.php?id=1">. 

 

Also, when I put in the code:

 

mysql_select_db("paintings", $con);

$id = (int) $_GET['id'];

$result = mysql_query("SELECT * FROM tinkers WHERE id=$id");

 

The WHERE part yields a blank page for me. 

 

Also, in addition to getting the coding right for the tinker.php page I am not sure what instructions are put in the view.php page.

 

Perhaps if I could have a simple example or a brief explanation of the concept it will help me move forward.

 

Thank you very much!

Link to comment
Share on other sites

When you code the link for your view.php page, you want to put it in as you stated (<a href="view.php?id=#">)

 

On your view.php page, your code should look like this:

 

mysql_select_db("paintings", $con);
$result = mysql_query("SELECT * FROM tinkers WHERE id='".$_GET['id']."'") or die(mysql_error());

 

That should get your query working correctly.

Link to comment
Share on other sites

Thank you so much for answering.  Okay, that helped me alot with the concept and my links are working just fine now. 

 

However, my view.php page is still blank.  When I do a view source it is empty (other than the html & body, etc tags).  The address is correct at the top.  Any thoughts?  View.php code is:

 

<?php

$con = mysql_connect("");

 

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("paintings", $con);

$result = mysql_query("SELECT * FROM tinkers WHERE id='".$_GET['id']."'") or die(mysql_error());

 

while($row = mysql_fetch_array($result))

{

$row['Title'] .  "<br>\n".

        $row['Medium'] . "<br>\n".

        $row['Size'] . "<br>\n";

}

 

 

 

 

mysql_close($con);

?>

 

 

My main page if it helps is:  www.sharondross.com/images/tinker/tinker.php

Link to comment
Share on other sites

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.