MySQL Forums
Forum List  »  PHP

PROBLEM CONCATENATING COLUMNS USING MYSQL AND PHP
Posted by: VALERIE IYOMIEJU
Date: October 02, 2007 07:17AM

Hi, please i need help.
I am trying to select data from a admissions table which contains rows- first_name, last_name, other_names, exam_no, course, college. I want all the names concatenated and displayed in a column called names but the problem is when i try to use CONCAT and run the srcipt nothing is diplayed on my browser but if i select the columns without concatenating them i get a result. Please can anyone help me go through the script below and let me know if i am omitting something or not doing it right?
thank you.

<?php require_once('Connections/new.php'); ?>
<?php
$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

mysql_select_db($database_new, $new);
$query_Recordset1 = "SELECT CONCAT(last_name, " ", first_name, " ", other_names) as names, college, course FROM admissions ORDER BY college, course, names ";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $new) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
?>
<table width="70%" border="1" cellspacing="3" cellpadding="3">
<tr>
<td>names</td>
<td>college</td>
<td>course</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_Recordset1['names']; ?></td>
<td><?php echo $row_Recordset1['college']; ?></td>
<td><?php echo $row_Recordset1['course']; ?></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
<?php
mysql_free_result($Recordset1);
?>


when i run the query without concatenating the columns i get result.
i.e. when i run the code below:

<?php require_once('Connections/new.php'); ?>
<?php
$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

mysql_select_db($database_new, $new);
$query_Recordset1 = "SELECT first_name, last_name, other_names, course, college FROM admissions ORDER BY college ASC";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $new) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
?>
<table width="70%" border="1" cellspacing="3" cellpadding="3">
<tr>
<td>Last Name </td>
<td>First Name </td>
<td>Other Names </td>
<td>Course</td>
<td>College</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_Recordset1['first_name']; ?></td>
<td><?php echo $row_Recordset1['last_name']; ?></td>
<td><?php echo $row_Recordset1['other_names']; ?></td>
<td><?php echo $row_Recordset1['course']; ?></td>
<td><?php echo $row_Recordset1['college']; ?></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
<?php
mysql_free_result($Recordset1);
?>

Options: ReplyQuote


Subject
Written By
Posted
PROBLEM CONCATENATING COLUMNS USING MYSQL AND PHP
October 02, 2007 07:17AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.