Get more than 1 data entry from DB using PHP


Joined
Jun 11, 2018
Messages
1
Reaction score
0
Hi all,

I am trying to get multiple rows data which has same id. So the same id can be allocated to different entries and I need to display this.

The code as follows:
<?php require_once('Connections/eam.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

$colname_rsMaintenanceAsset = "-1";

if (isset($_GET['recordID'])) {
$colname_rsMaintenanceAsset = $_GET['recordID'];
}
mysql_select_db($database_eam, $eam);
$query_rsMaintenanceAsset = sprintf("SELECT * FROM maintenance_history WHERE maint_id = %s", GetSQLValueString($colname_rsMaintenanceAsset, "int"));
$rsMaintenanceAsset = mysql_query($query_rsMaintenanceAsset, $eam) or die(mysql_error());
$row_rsMaintenanceAsset = mysql_fetch_assoc($rsMaintenanceAsset);
$totalRows_rsMaintenanceAsset = mysql_num_rows($rsMaintenanceAsset);
}

$pageTitle="Maintenance History"; ?>



<?php include('includes/header.php'); ?>
<h3>Maintenance history for Asset ID: <?php echo $colname_rsMaintenanceAsset; ?></h3>
<table class="table1">
<tr>
<th>Maintenance ID</th>
<th>Date Completed</th>
<th>By</th>
<th>Checklist</th>
<th>Comments</th>
<th>SPARE</th>
<th>View &nbsp; </th>
</tr>
<?php do { ?>
<tr onmouseover="this.bgColor='#F2F7FF'" onmouseout="this.bgColor='#FFFFFF'";>
<td> <?php echo $row_rsMaintenanceAsset['id']; ?>&nbsp; </td>
<td> <?php echo $row_rsMaintenanceAsset['date_completed']; ?>&nbsp; </td>
<td> <?php echo $row_rsMaintenanceAsset['by_staff']; ?>&nbsp; </td>
<td> <?php echo $row_rsMaintenanceAsset['maint_checklist']; ?>&nbsp; </td>
<td> <?php echo $row_rsMaintenanceAsset['maint_comm']; ?>&nbsp; </td>
<td> <?php echo $row_rsMaintenanceAsset['status']; ?>&nbsp; </td>


<td> <a href="HardwareDetail.php?recordID=<?php echo $row_rsMaintenanceAssets['maint_id']; ?>">View</a></td>
</tr>
<?php } while ($row_rsMaintenanceAssets = mysql_fetch_assoc($rsMaintenanceAssets)); ?>
</table>

Any help appreciated :)
 
Ad

Advertisements

Joined
Jul 12, 2020
Messages
23
Reaction score
2
you're looking for a one-to-many data table setup. Like a single user that has subscribed to multiple channels. would look something like:
user_channels
channel_id | user_id| channel_name
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top