Jump to content

(For new php user's only) how to get one page entry to another example ok.


redarrow

Recommended Posts

Lets exsplain how to use a link to see entrys from a page to another ok.

.

 


<?php

//database connection

$db=mysql_connect("localhost","username","password");
mysql_select_db("database_name",$db);

//select statement example ok all book entry's lol.
$query1="select * from books ";
$result=mysql_query(query1);

//while loop to get all the books
while($record=myslq_fetch_assoc($result)){

// echo book information ok title price and a link to see that book information.
echo" ".$record['book_title']," <br> ".$record['price']." <br> 
<a href='read_more.php?id=".$record['id']."'>More Info</a><br><br>";

}

?>

 

Now where going to a page read_more.php to view the book information

and use the id what is in the link to get the book full information.

 

read_more.php

<?php

// database connection
$db=mysql_connect("localhost","username","password");
mysql_select_db("database_name",$db);

//select statement that gets the books from the id in the url.
$query1="select * from books where id=".$_GET[ 'id']." ";
$result=mysql_query($query1);

//read that book we just selected.
while($rec=myslq_fetch_assoc($result)){

// echo book information that was selected.
echo" ".$rec['book_title']." <br> ".$rec['price']." <br> 
".$rec['date_book_was_made']."<br>".$rec['book_description']." <br>";
}

?>

 

now you can see the book that the user selected from a url in the url we use a

varable what was the id of the book then we went to a page and looked at the book

that was selected from the link.

 

That it ok.

Hey

 

Whats wrong here?

 

 

//select statement example ok all book entry's lol.

$sql = "SELECT * FROM shops";

$data = mysql_query($sql);

while($record = mysql_fetch_assoc($data))

 

//while loop to get all the books

while($record=myslq_fetch_assoc($result)){

 

$id = $record['id'];

$name = $record['name'];

$picture = $record['picture'];

$rating = $record['rating'];

$sdesc = $record['sdesc'];

 

 

// echo book information ok title price and a link to see that book information.

 

echo '

 

echo '$id<br>$name<br><a href='read_more.php?id=$id'>More Info</a><br><br>';

 

}

 

?>

 

Hey

 

Whats wrong here?

 

 

//select statement example ok all book entry's lol.

$sql = "SELECT * FROM shops";

$data = mysql_query($sql);

while($record = mysql_fetch_assoc($data))

 

//while loop to get all the books

while($record=myslq_fetch_assoc($result)){

 

$id = $record['id'];

$name = $record['name'];

$picture = $record['picture'];

$rating = $record['rating'];

$sdesc = $record['sdesc'];

 

 

// echo book information ok title price and a link to see that book information.

 

echo '

 

echo '$id<br>$name<br><a href='read_more.php?id=$id'>More Info</a><br><br>';

 

}

 

?>

 

 

The [ code ] and [ /code ] tags are your friend.

 

What was wrong was you added an extra while loop. Here is how it should look.

<?php
//select statement example ok all book entry's lol.
$sql = "SELECT * FROM shops";
$data = mysql_query($sql);
while($record = mysql_fetch_assoc($data)) {
$id = $record['id'];
$name = $record['name'];
$picture = $record['picture'];
$rating = $record['rating'];
$sdesc = $record['sdesc'];


// echo book information ok title price and a link to see that book information.

echo $id .  $name . "<a href=read_more.php?id=".$id.">More Info[/url]";

}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.