Fetch from Database help

Hi Guys,

I am new to PHP but trying to pick up as im trying to build a system for my work.

This is an easy one…i think. What I would like to be able to do is pull down data from a database and display it in a table (ive done that). Then I would like to be able to click on one of the rows of data that then takes me to a fresh table with more information.

I understand how it would work, just cant seem to code it.

Select whole database - Display in table
Onclick row
Select from database where row = what ever i clicked on.

I want to be able to click the whole row as this is going to be on a touch screen.

This is my code for the first bit (probs a bit messy)

[code]

<?php $con=mysqli_connect("localhost","root","","database"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $result = mysqli_query($con,"SELECT * FROM table"); echo ""; while($row = mysqli_fetch_array($result)) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
Job Ref Client Site Job Description Start Date Duration Machines Technicians
" . $row['jobref'] . "" . $row['client'] . "" . $row['site'] . "" . $row['Job_description'] . "" . $row['start_date'] . "" . $row['duration'] . "" . $row['machines'] . "" . $row['technicians'] . "
"; mysqli_close($con); ?> [/code]

Thanks,

Tim

The simplest thing you can do is make your results a hyperlink that links to another page just like you have now with the query for the details of that records id. It is not the optimum way, just a simple way to get you going. It is possible to do everything on one page.

[php] echo "

<a href=“secondpage.php?id={$row[‘id’]}”>{$row[‘jobref’] } "; [/php]

ONE way to do the whole row as a link:

[code]

data data2
[/code]

Hi Bananamen,

The data will be constantly changing, so how would I get the 2nd page to know which row has been clicked and therefore which data to display. Im still a relative novice to this.

The data may change, but the unique id for each record should never change.

look at the link I posted. The row id is part of the url (query string) that you send to page 2.

On page two in its most basic form is

[php]$rowId=$_GET[‘id’];[/php]

Now you can use $rowId in your query.

SELECT column names FROM tablename WHERE id=$rowId;

I meant to say thanks to this one before.

Your solution worked great :slight_smile:

I then added a jQuery script to allow me to use the whole line/row as a link and it worked.

Sponsor our Newsletter | Privacy Policy | Terms of Service