Jump to content

Simple PHP help


timprice

Recommended Posts

Hi all,

I am new to php, and just using some help guides to try and build a basic system.

What I would like is an output page to display a table with selected data in (that I can do)

I would how ever like the the table rows to be links to another page which contains more information of which ever row I clicked.

eg:/

output.php
 Job Ref | Client | Site | Description   <------click this row of data to take you to the next page.

output2.php
Start Date | Duration | Machines | Technicians <------- This page only shows the data taken from the row above.

This is my code for the 1st page (output.php) Basic Code

 

<html>
	<meta http-equiv="refresh" content="120">
</html>

<?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 "<table border='1'>
<tr>
<th>Job Ref</th>
<th>Client</th>
<th>Site</th>
<th>Job Description</th>
</tr>";

while($row = mysqli_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['jobref'] . "</td>";
  echo "<td>" . $row['client'] . "</td>";
  echo "<td>" . $row['site'] . "</td>";
  echo "<td>" . $row['Job_description'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysqli_close($con);
?> 

Thanks for any help guys.

Link to comment
https://forums.phpfreaks.com/topic/286281-simple-php-help/
Share on other sites

I have been trying this but I dont think its is carrying over the row ID to the seconds page.

 

while($row = mysqli_fetch_array($result))
  {
  echo "<tr>";
  echo "<td><a href=\"secondpage.php?id={$row['id']}\">{$row['jobref'] }</a> </td>";
  echo "<td><a href=\"secondpage.php?id={$row['id']}\">{$row['client'] }</a> </td>";
  echo "<td>" . $row['site'] . "</td>";
  echo "<td>" . $row['Job_description'] . "</td>";

  echo "</tr>";
  }
echo "</table>";

mysqli_close($con);
?> 

Secondpage

<?php

$con=mysqli_connect("localhost","root","","database");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$rowId=$_GET['id'];
  
$result = mysqli_query($con,"SELECT * FROM table WHERE id=$rowId");

echo "<table border='1'>
<tr>
<th>Job Ref</th>
<th>Client</th>
<th>Site</th>
<th>Job Description</th>
</tr>";

while($row = mysqli_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['jobref'] . "</td>";
  echo "<td>" . $row['client'] . "</td>";
  echo "<td>" . $row['site'] . "</td>";
  echo "<td>" . $row['Job_description'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysqli_close($con);
?> 
Link to comment
https://forums.phpfreaks.com/topic/286281-simple-php-help/#findComment-1469365
Share on other sites

 

 

  1. echo "<td><a href=\"secondpage.php?id={$row['id']}\">{$row['jobref'] }</a> </td>";
  2. echo "<td><a href=\"secondpage.php?id={$row['id']}\">{$row['client'] }</a> </td>";

That should pass the rows id to secondpage provided you do have a column called id in your database, which holds the records id.

 

The code used in secondpage.php should work, however I'd use the following when getting the id

$rowId=intval($_GET['id']);
Link to comment
https://forums.phpfreaks.com/topic/286281-simple-php-help/#findComment-1469383
Share on other sites

Arrrrh, right yeah it was failing becuase 'id' was in caps in the database.
Ok so thats working, but it makes each of those as hyperlinks to a new page which while in essence is fine, what I would like is for the whole row to be a link.
Im not sure how to do that.

Can I put that code say here:

 

    while($row = mysqli_fetch_array($result))
    {
    echo "<tr><a href=\"secondpage.php?id={$row['id']}\">";
    echo "<td>" . {$row['jobref'] }. "</td>";
    echo "<td>" . {$row['client'] }. "</td>";
    echo "<td>" . $row['site'] . "</td>";
    echo "<td>" . $row['Job_description'] . "</td>";
     
    echo "</a></tr>";
    }
    echo "</table>";
     
    mysqli_close($con);
    ?> 

To make the whole row a link not just the text?

Link to comment
https://forums.phpfreaks.com/topic/286281-simple-php-help/#findComment-1469385
Share on other sites

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.