Board index   FAQ   Search  
Register  Login
Board index php forum :: Database phpMyAdmin

Retrieving DATA from MySQL DATABASE

How to use phpmyadmin.... phpmyadmin related arguments. Even phpMyAdmin issues

Moderators: macek, egami, gesf

Retrieving DATA from MySQL DATABASE

Postby arilwan » Thu Jul 07, 2011 1:29 am

Hi all,

Please I need some help here. I'm retrieving data from mysql table "bookcopy" and displaying list of books with their prices. I want users to be able to view details of any book they clicked on, on a page I called detail.php.

The list is displayed successfully, how ever, if you click any of the books, it shows the details of the first book on the list, on matter which one you select. Can anyone help me out please?

Below is the code I used. I ask this question 2weeks ago, but haven't receive any response.

Thank you.


Code: Select all
<html>
<head>
<title>SHUBooks</title>
</head>
<body>

<?php
session_start();
include('connect.php');
$query = "SELECT * FROM bookcopy";
$result = mysql_query($query) or die(mysql_error());
?>

<div align="center"><b>Thank you for visiting SHUBooks! Please see our list of available Books below, and click to view Book
details:
</b><br><br>
<table border="1">
<?php
echo "<tr>";
echo "<td bgcolor=\"red\" width=\"30\">";
echo "<font color=\"white\"><b>";
echo "Back Cover";
echo "<font></b></td>";
echo "<td bgcolor=\"red\" with=\"50\">";
echo "<font color=\"white\"><b>";
echo "Book Title";
echo "<font></b></td>";
echo "<td bgcolor=\"red\" width=\"20\"><td>";
echo "</tr>";

//display books with prices

while($row = mysql_fetch_array($result))
{
//extract($row);
echo "<tr>";
echo "<a href=\"detail.php?bookId=".$row['bookId']."\">";
echo "<td><em>BOOK IMAGE</em></td>";
echo "<td>";
echo "<a href=\"detail.php?bookId=".$row['bookId']."\">";
echo $row['bookTitle'];
echo "</td>";
echo "<td>";
echo "<a href=\"detail.php?bookId=".$row['bookId']."\">";
echo "View Details</a>";
echo "</td>";
echo "</tr>";

}

?>
</table>
<?php
echo "<hr size=\"1\" color=\"red\" NOSHADE>";
echo "<form action=\"cart.php\">";
echo "<input type=\"submit\" value=\"My Shopping Cart &gt;&gt;\">";
 echo "<input type=\"hidden\" name=\"bookId\" value=".$row['bookId'].">";
echo "</form>";
?>

</body>
</html>
arilwan
New php-forum User
New php-forum User
 
Posts: 6
Joined: Wed Jun 29, 2011 3:28 am

Re: Retrieving DATA from MySQL DATABASE

Postby egami » Thu Jul 07, 2011 4:15 am

I need to see your code for detail.php.

Your form doesn't do anything at the bottom except to push one single (the last one the db feeds) to cart.php. So that's a fubar situation there.
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: Retrieving DATA from MySQL DATABASE

Postby arilwan » Thu Jul 07, 2011 8:31 am

Below is the code for detail.php page,

Thank you.

Code: Select all
<?php
if(!session_id()){
session_start();
include('connect.php');
//$bookId=$_REQUEST['bookId'];

}
?>
<html>
<head>
<title><?php echo $bookTitle ?></title>
</head>
<body>
<?php
//get variable paased through the URL



//get info about the book we want
$query = "SELECT * FROM bookcopy";

$results =mysql_query($query) or die(mysql_error());
$row= mysql_fetch_array($results);

?>

<div align="center" >
<table cellpadding="5" width="80%">
<tr>
<td>BOOK IMAGE</td>
<td><strong><?php echo $row['bookTitle']; ?></strong><br>
<?php echo $row['ISBN']; ?><br>
<br>Book Price: £<?php echo $row['bookPrice']; ?><br>

<form method="POST" action="modcart.php">
<input type="hidden" name="bookId" value="<?php echo $row['bookId'] ?>">
<input type="hidden" name="userId" value="<?php echo $row['userId'] ?>">
<input type="hidden" name="bookTitle" value="<?php echo $row['bookTitle'] ?>">
<input type="hidden" name="bookPrice" value="<?php echo $row['bookPrice'] ?>">   
<input type="submit" name="Submit" value="Add to My Cart"> 
</form>

<form method="POST" action="cart.php">
<input type="submit" name="Submit" value="View My Cart">
<input type="hidden" name="cartId" value="<?php echo $row['cartId'] ?>">
<input type="hidden" name="bookId" value="<?php echo $row['bookId'] ?>">
</form>
</td>
</tr>
</table>
<hr width="450" color="green">
<p><a href="books.php">Go Back</a></p>
</div>
</body>
</html>
arilwan
New php-forum User
New php-forum User
 
Posts: 6
Joined: Wed Jun 29, 2011 3:28 am

Re: Retrieving DATA from MySQL DATABASE

Postby egami » Fri Jul 08, 2011 9:55 am

Your code doesn't do anything. and I mean, anything.

You're going to need to grab the ID of the book that was clicked..
Pull that information from the DB, and then display it.
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: Retrieving DATA from MySQL DATABASE

Postby raghuram » Mon Jul 18, 2011 3:12 am

Creating database and database tables in PHP MYADMIN is very easy and faster than doing in mysql console and sqlite...To retrieve data from database follow the coding:
<?php
$con=mysql_connect("hostname","username","password");
mysql_select_db("databasename",$con);
//create table
$t="create table hi();"
mysql_query($t,$con);
//insert values into table
$i="insert into hi values();"
mysql_query($i,$con);
//write a query
$sql="select * from hi";
$result=mysql_query($sql,$con);
while($re=mysql_fetch_array($result))
{
echo $re[''];//output the field names
}
?>
Cegonsoft Interview Orientation

Cegonsoft
raghuram
New php-forum User
New php-forum User
 
Posts: 6
Joined: Thu Jun 16, 2011 11:13 pm


Return to phpMyAdmin

Who is online

Users browsing this forum: No registered users and 0 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.