Missing the result printed from database - php

My purpose is search book type from input keyboard and count it. I have error: counting the number of book is right but when print, it miss some result. For example, I put 'f' it show 7 result( right) however it print only 2 two result. Here is my code:
<form action="" method="POST">
Enter type of book here:<input type="text" size="20" name="sbt"> <br />
<input type="submit" name="sb" value="Search">
</form>
<table align="center" border="1" width="600">
<thead><tr align="center">
<tr align="center">
<td><b>Book ID</b></td>
<td><b>Book Title</b></td>
<td><b>Book Author</b></td>
<td><b>Pulished Year</b></td>
<td><b>Book Type</b></td>
<td><b>Status</b></td>
</tr>
<?php
if (isset($_POST['sb'])) {
$s="";
if ($_POST['sbt'] == null) {
echo "Please re-enter <br>";
} else
{
$s = $_POST['sbt'];
}
$q = "SELECT * FROM book WHERE book_type LIKE '%$s%' ";
$r= mysqli_query($conn,$q);
while($row = mysqli_fetch_array($r)) {
?>
<tr align="center">
<td><?php echo $row['book_no'];?></td>
<td><?php echo $row['book_title'];?></td>
<td><?php echo $row['book_author'];?></td>
<td><?php echo $row['book_year'];?></td>
<td><?php echo $row['book_type'];?></td>
<td>
<?php
if ($row['book_quantity'] == 1) {
echo "Available";
}
else {
echo "Not available";
}
?>
</td>
<?php
$c=" SELECT COUNT(DISTINCT(book_no)) AS totaltype FROM book WHERE book_type LIKE '%$s%'";
$s= mysqli_query($conn, $c);
if (mysqli_num_rows($s)> 0 )
{
$row2= mysqli_fetch_array($s);
echo " Total book type result:"."{$row2['totaltype']}";
}
}
?>
<?php } ?>
</table>

Remove "%" before $s and try.
for example:
$query = mysql_query("SELECT * FROM table WHERE the_number LIKE '$yourPHPVAR%'");

Related

How to SELECT / QUERY multiple names from MySQL

Good day folks,
Please I'm trying to implement something simple but I'm not finding the proper solution in PHP. I would like to ask for some advises, please.
I have one list of servers in the Array/Vector called $lines, now I would like to SELECT each server name in a MySQL DB in order to collect additional infos.
Could you please give me ideas regarding how to do a loop from the server names in, to SELECT / QUERY each one ?
Thanks!!
<html>
<head>
</head>
<body>
<form name="form1" method="post">
<textarea rows="10" name="servers[]" cols="50" ></textarea>
<input type="submit" name="submit" value="Submit" />
</form>
<?php
$con=mysqli_connect("hostxxxx","userxxxx","xxxxxxxx","xxxxxxx");
//Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if(isset($_POST["submit"]))
{
if(!empty($_POST["servers"]))
{
echo '<h4>You have selected the following Servers:</4><br>';
$submitted_array = array_keys($_POST["servers"]);
$lines = explode(PHP_EOL, $_POST["servers"][$submitted_array[0]]);
foreach($lines as $servers)
{
echo ($servers."<br>");
}
}
else
{
echo 'Please write something';
}
}
?>
</body>
</html>
I've got the result as I needed, I hope it can help:
<body>
<form name="form1" method="post">
<textarea rows="1000" name="servers[]" cols="100" style="width:300px;height:300px;"></textarea>
<input type="submit" name="submit" value="Submit" />
</form>
<?php
$con=mysqli_connect("hostxxxxx:portxx","userx","passxx","msdb");
//Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if(isset($_POST["submit"]))
{
if(!empty($_POST["servers"]))
{
echo '<h4>You have selected the following Servers:</4><br>';
$submitted_array = array_keys($_POST["servers"]);
//BREAKING IN AN ARRAY
$lines = explode(PHP_EOL, $_POST["servers"][$submitted_array[0]]);
//foreach($lines as $servers)
//{
//echo ($servers."<br>");
//}
//REMOVING BLANK SPACES:
function trim_value(&$value)
{
$value = trim($value);
}
//ADDING QUOTES BETWEEN THE VALUES
function add_quotes($str) {
return sprintf("'%s'", $str);
}
//REMOVING BLANK LINES
array_walk($lines, 'trim_value');
$VCSAC2 = "VCSAC2";
$LPAR = "LPAR";
$HOSTF = "HOSTF";
$CLASSG = "CLASSG";
$IP = "IP";
$STATUS = "STATUS";
//USING IMPLODE
//$sql=sprintf("SELECT * FROM main WHERE HOSTF IN (".implode(',', $lines).")");
$sql=sprintf("SELECT * FROM main WHERE HOSTF IN (".implode(',', array_map('add_quotes',$lines)).")");
//USED TO CHECK SQL SINTAX
//echo $sql;
$result=mysqli_query($con,$sql);
}
else
{
echo 'Please write something';
}
}
?>
<table id="demo1" cellpadding="0" cellspacing="0" style="width:100%" style="font-size:13px">
<thead>
<tr>
<th align=left>HostName</th>
<th align=left>VCS</th>
<th align=left>LPAR</th>
<th align=left>IP</th>
<th align=left>Class</th>
</tr>
</thead>
<?php while($dado = mysqli_fetch_array($result)) {?>
<tbody>
<tr>
<td align=left style="font-size:14px"><?php echo $dado[$HOSTF]; ?></td>
<td align=left style="font-size:14px"><?php echo $dado[$VCSAC2]; ?></td>
<td align=left style="font-size:14px"><?php echo $dado[$LPAR]; ?></td>
<td align=left style="font-size:14px"><?php echo $dado[$IP]; ?></td>
<td align=left style="font-size:14px"><?php echo $dado[$CLASSG]; ?></td>
</tr>
</tbody>
<?php } ?>
</table> <br><br>
</body>

Multiple Checkboxes Columns Updating Multiple SQL Rows

I've never had issues programming PHP SQL updates when updating multiple rows of data with multiple columns, but for some reason this section of coding is killing me as it is nothing more than checkboxes for the end user to check and/or uncheck. I've include portions of the code below as the full code is over 50+ columns wide of checkboxes and can range from 1-200 rows.
Everything displays/runs the way its supposed to but the updating isnt functioning properly ... example: if there is 5 rows (each with a unique trackingid) and I check the checkbox for the 4th row on update it says that the 1st checkbox was checked and NOT the 4th row.
<?php if (!isset($_POST['trackingid'])) { ?>
<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post" enctype="multipart/form-data" class="form-horizontal" id="form"><input type="hidden" name="id" value="<?php echo $id; ?>">
<table class="table table-striped">
<thead>
<tr>
<td class="rotate-alt"></td>
<td class="rotate-alt2"><div><span></span></div></td>
<td class="rotate-alt2"><div><span></span></div></td>
<td class="rotate-alt2"><div><span></span></div></td>
<td class="rotate-alt2"><div><span></span></div></td>
<td class="rotate-alt2"><div><span></span></div></td>
<td class="rotate-alt"><div><span>Glass</span></div></td>
<td class="rotate-alt"><div><span>Glass - SDL</span></div></td>
<td class="rotate-alt"><div><span>Mill - S&R</span></div></td>
</tr>
</thead>
<tbody>
<?php $result = sqlsrv_query($conn, "SELECT id, [Order Number], [Door Number], [Qty Display], [Interior or Exterior], [Style], Species_DD_Desc, [Mill Batch Nbr],
[Glass Completed], [Glass Completed By], [Glass STD Hrs], [SDL Completed], [SDL Completed By], [SDL STD Hrs],
[Mill Completed], [Mill Completed By], [Mill STD Hrs]
FROM PD_Tracking
WHERE [Order Number] = '$id'
ORDER BY [Door Number], [Qty Display], [Mill Batch Nbr]");
$i=0;
while ($list = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)){ ?>
<tr>
<td class="center">
<input type="checkbox" onclick="$('input[id=\'selid<?php echo $i; ?>\']').attr('checked', this.checked);">
<input type="hidden" name="trackingid[]" value="<?php echo $list['id']; ?>">
</td>
<td class="center"><?php echo $list['Door Number']; ?></td>
<td class="center"><?php echo $list['Qty Display']; ?></td>
<td class="center"><?php echo $list['Interior or Exterior']; ?></td>
<td class="center"><?php echo $list['Style']; ?></td>
<td class="center"><?php echo $list['Species_DD_Desc']; ?></td>
<td class="center">
<?php if (($list['Glass STD Hrs']>0) && (!isset($list['Glass Completed']))){ ?>
<input type="checkbox" name="glass[]" id="selid<?php echo $i; ?>">
<?php } else if (($list['Glass STD Hrs']>0) && ($list['Glass Completed'] > ' ')){ ?>
<input type="checkbox" name="glass[]" checked="checked" id="selid<?php echo $i; ?>">
<?php } else { ?>
NR
<?php } ?>
</td>
<td class="center">
<?php if (($list['SDL STD Hrs']>0) && (!isset($list['SDL Completed']))){ ?>
<input type="checkbox" name="sdl[]" id="selid<?php echo $i; ?>">
<?php } else if (($list['SDL STD Hrs']>0) && ($list['SDL Completed'] > ' ')){ ?>
<input type="checkbox" name="sdl[]" checked="checked" id="selid<?php echo $i; ?>">
<?php } else { ?>
NR
<?php } ?>
</td>
<td class="center">
<?php if (($list['Mill STD Hrs']>0) && (!isset($list['Mill Completed']))){ ?>
<input type="checkbox" name="mill[]" id="selid<?php echo $i; ?>">
<?php } else if (($list['Mill STD Hrs']>0) && ($list['Mill Completed'] > ' ')){ ?>
<input type="checkbox" name="mill[]" checked="checked" id="selid<?php echo $i; ?>">
<?php } else { ?>
NR
<?php } ?>
</td>
</tr>
<?php ++$i;
} ?>
</tbody>
</table>
<?php } // END if (!isset($_POST['trackingid'])) {
if (isset($_POST['trackingid'])) {
$query = sqlsrv_query($conn, "SELECT * FROM users WHERE id=".$_SESSION['auid']."");
$row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC);
$employee_num = $row['Employee Number'];
$size = count($_POST['trackingid']);
for($i=0; $i < $size; $i++){
$trackingid = $_POST['trackingid'][$i];
$query = "UPDATE PD_Tracking SET ";
if(isset($_POST['glass'][$i])){
$query .= "[Glass Completed]='$date_time_entered', [Glass Completed By]='$employee_num', ";
} else {
$query .= "[Glass Completed]= NULL, [Glass Completed By]= NULL, ";
}
if(isset($_POST['sdl'][$i])){
$query .= "[SDL Completed]='$date_time_entered', [SDL Completed By]='$employee_num', ";
} else {
$query .= "[SDL Completed]= NULL, [SDL Completed By]= NULL, ";
}
if(isset($_POST['mill'][$i])){
$query .= "[Mill Completed]='$date_time_entered', [Mill Completed By]='$employee_num' ";
} else {
$query .= "[Mill Completed]= NULL, [Mill Completed By]= NULL ";
}
$query .= "WHERE id='$trackingid'";
$query = sqlsrv_query($conn, $query);
} // END for($i=0; $i < $size; $i++){?>
<SCRIPT LANGUAGE='JavaScript'>
<!-- Begin
window.location = '<?php echo $_SERVER['REQUEST_URI']; ?>&success=edit';
// End -->
</script>
<?php } // END if (isset($_POST['trackingid'])) { ?>

PHP echo results in new table, not new row

Currently the below puts everything into rows, I am wondering if there is a way to put these as individual tables every time instead of rows?
I am used to echo everything to rows as everything I have dealt with so far, is perfectly fine. But now I am at a point where it would be better to show all as individual tables.
I might not be explaining myself very well, sorry if not.
<table width="75%" border="0" cellpadding="0" cellspacing="2" class="table">
<tr align="center">
<td class="header"><center>Patch Version</center></td>
<td class="header"><center>Patch Date</center></td>
<td class="header"><center>Update By</center></td>
<?php if ($userlvl >= 3) { ?><td class="header"><center>Admin Settings</center></td></tr> <?php } else { } ?>
</tr>
<?
$result = mysql_query("SELECT * FROM updates WHERE del ='0' ORDER BY id DESC") or die(mysql_error());
while($row = mysql_fetch_array( $result )) {
?>
<tr>
</label></td>
<td class="header"><center><h4><? echo $row['patchversion'] ?></h3></center></td>
<td class="header"><center><h3><? echo $row['updatetime'] ?></h3></center></td>
<td class="header"><center><h4><? echo $row['addedby']?></h4></td>
<?php if ($userlvl >= 3) { ?><td class="header"><center><h4> <?php } else { } ?>
<?php if ($userlvl >= 3){ echo "( Edit )" ." - ". "( X )"; } else { } ?></center></td>
<tr><td class="cell" colspan="50"><? echo $row['news']?></td>
</tr>
<?php }
?>
</table>
Just move the table tags within your while loop, something like this for example:
<?php
while($row = mysql_fetch_array( $result )) {
?>
<table>
<tr>
<td class="header"><center><h4><? echo $row['patchversion'] ?></h3></center></td>
<td class="header"><center><h3><? echo $row['updatetime'] ?></h3></center></td>
<td class="header"><center><h4><? echo $row['addedby']?></h4></td>
<?php if ($userlvl >= 3) { ?><td class="header"><center><h4> <?php } else { } ?>
<?php if ($userlvl >= 3){ echo "( Edit )" ." - ". "( X )"; } else { } ?></center></td>
</tr>
</table>
<?php } ?>

Sort By Date last created and limit to five result

I am trying to do two things one is to Sort By Date last created the next one is to limit the the amount of data show to five (5) so ticket one, ticket two, ticket three, four, and five
I am making a drop down window that shows the last 5 ticket that was created and i am getting the information from below
Thank you for your help
<?php
if(!defined('OSTCLIENTINC') || !is_object($thisclient) || !$thisclient->isValid()) die('Access Denied');
$qstr='&'; //Query string collector
$status=null;
if(isset($_REQUEST['status'])) { //Query string status has nothing to do with the real status used below.
$qstr.='status='.urlencode($_REQUEST['status']);
//Status we are actually going to use on the query...making sure it is clean!
switch(strtolower($_REQUEST['status'])) {
case 'open':
case 'closed':
$status=strtolower($_REQUEST['status']);
break;
default:
$status=''; //ignore
}
} elseif($thisclient->getNumOpenTickets()) {
$status='open'; //Defaulting to open
}
$sortOptions=array('id'=>'`number`', 'subject'=>'subject.value',
'status'=>'ticket.status', 'dept'=>'dept_name','date'=>'ticket.created');
$orderWays=array('DESC'=>'DESC','ASC'=>'ASC');
//Sorting options...
$order_by=$order=null;
$sort=($_REQUEST['sort'] && $sortOptions[strtolower($_REQUEST['sort'])])?strtolower($_REQUEST['sort']):'date';
if($sort && $sortOptions[$sort])
$order_by =$sortOptions[$sort];
$order_by=$order_by?$order_by:'ticket_created';
if($_REQUEST['order'] && $orderWays[strtoupper($_REQUEST['order'])])
$order=$orderWays[strtoupper($_REQUEST['order'])];
$order=$order?$order:'ASC';
if($order_by && strpos($order_by,','))
$order_by=str_replace(','," $order,",$order_by);
$x=$sort.'_sort';
$$x=' class="'.strtolower($order).'" ';
$qselect='SELECT ticket.ticket_id,ticket.`number`,ticket.dept_id,isanswered, '
.'dept.ispublic, subject.value as subject,'
.'dept_name,ticket. status, ticket.source, ticket.created ';
$dynfields='(SELECT entry.object_id, value FROM '.FORM_ANSWER_TABLE.' ans '.
'LEFT JOIN '.FORM_ENTRY_TABLE.' entry ON entry.id=ans.entry_id '.
'LEFT JOIN '.FORM_FIELD_TABLE.' field ON field.id=ans.field_id '.
'WHERE field.name = "%1$s" AND entry.object_type="T")';
$subject_sql = sprintf($dynfields, 'subject');
$qfrom='FROM '.TICKET_TABLE.' ticket '
.' LEFT JOIN '.DEPT_TABLE.' dept ON (ticket.dept_id=dept.dept_id) '
.' LEFT JOIN '.TICKET_COLLABORATOR_TABLE.' collab
ON (collab.ticket_id = ticket.ticket_id
AND collab.user_id ='.$thisclient->getId().' )'
.' LEFT JOIN '.$subject_sql.' subject ON ticket.ticket_id = subject.object_id ';
$qwhere = sprintf(' WHERE ( ticket.user_id=%d OR collab.user_id=%d )',
$thisclient->getId(), $thisclient->getId());
if($status){
$qwhere.=' AND ticket.status='.db_input($status);
}
$search=($_REQUEST['a']=='search' && $_REQUEST['q']);
if($search) {
$qstr.='&a='.urlencode($_REQUEST['a']).'&q='.urlencode($_REQUEST['q']);
if(is_numeric($_REQUEST['q'])) {
$qwhere.=" AND ticket.`number` LIKE '$queryterm%'";
} else {//Deep search!
$queryterm=db_real_escape($_REQUEST['q'],false); //escape the term ONLY...no quotes.
$qwhere.=' AND ( '
." subject.value LIKE '%$queryterm%'"
." OR thread.body LIKE '%$queryterm%'"
.' ) ';
$deep_search=true;
//Joins needed for search
$qfrom.=' LEFT JOIN '.TICKET_THREAD_TABLE.' thread ON ('
.'ticket.ticket_id=thread.ticket_id AND thread.thread_type IN ("M","R"))';
}
}
$total=db_count('SELECT count(DISTINCT ticket.ticket_id) '.$qfrom.' '.$qwhere);
$page=($_GET['p'] && is_numeric($_GET['p']))?$_GET['p']:1;
$pageNav=new Pagenate($total, $page, PAGE_LIMIT);
$pageNav->setURL('tickets.php',$qstr.'&sort='.urlencode($_REQUEST['sort']).'&order='.urlencode($_REQUEST['order']));
//more stuff...
$qselect.=' ,count(attach_id) as attachments ';
$qfrom.=' LEFT JOIN '.TICKET_ATTACHMENT_TABLE.' attach ON ticket.ticket_id=attach.ticket_id ';
$qgroup=' GROUP BY ticket.ticket_id';
$query="$qselect $qfrom $qwhere $qgroup ORDER BY $order_by $order LIMIT ".$pageNav->getStart().",".$pageNav->getLimit();
//echo $query;
$res = db_query($query);
$showing=($res && db_num_rows($res))?$pageNav->showing():"";
$showing.=($status)?(' '.ucfirst($status).' Tickets'):' All Tickets';
if($search)
$showing="Search Results: $showing";
$negorder=$order=='DESC'?'ASC':'DESC'; //Negate the sorting
?>
<h1>Tickets</h1>
<br>
<form action="tickets.php" method="get" id="ticketSearchForm">
<input type="hidden" name="a" value="search">
<input type="text" name="q" size="20" value="<?php echo Format::htmlchars($_REQUEST['q']); ?>">
<select name="status">
<option value="">— Any Status —</option>
<option value="open"
<?php echo ($status=='open')?'selected="selected"':'';?>>Open (<?php echo $thisclient->getNumOpenTickets(); ?>)</option>
<?php
if($thisclient->getNumClosedTickets()) {
?>
<option value="closed"
<?php echo ($status=='closed')?'selected="selected"':'';?>>Closed (<?php echo $thisclient->getNumClosedTickets(); ?>)</option>
<?php
} ?>
</select>
<input type="submit" value="Go">
</form>
<a class="refresh" href="<?php echo Format::htmlchars($_SERVER['REQUEST_URI']); ?>">Refresh</a>
<table id="ticketTable" width="800" border="0" cellspacing="0" cellpadding="0">
<caption><?php echo $showing; ?></caption>
<thead>
<tr>
<th width="70" nowrap>
Ticket #
</th>
<th width="100">
Create Date
</th>
<th width="80">
Status
</th>
<th width="300">
Subject
</th>
<th width="150">
Department
</th>
<th width="100">Phone Number</th>
</tr>
</thead>
<tbody>
<?php
if($res && ($num=db_num_rows($res))) {
$defaultDept=Dept::getDefaultDeptName(); //Default public dept.
while ($row = db_fetch_array($res)) {
$dept=$row['ispublic']?$row['dept_name']:$defaultDept;
$subject=Format::htmlchars(Format::truncate($row['subject'],40));
if($row['attachments'])
$subject.=' <span class="Icon file"></span>';
$ticketNumber=$row['number'];
if($row['isanswered'] && !strcasecmp($row['status'],'open')) {
$subject="<b>$subject</b>";
$ticketNumber="<b>$ticketNumber</b>";
}
$phone=Format::phone($row['phone']);
if($row['phone_ext'])
$phone.=' '.$row['phone_ext'];
?>
<tr id="<?php echo $row['ticket_id']; ?>">
<td class="centered">
<a class="Icon <?php echo strtolower($row['source']); ?>Ticket" title="<?php echo $row['email']; ?>"
href="tickets.php?id=<?php echo $row['ticket_id']; ?>"><?php echo $ticketNumber; ?></a>
</td>
<td> <?php echo Format::db_date($row['created']); ?></td>
<td> <?php echo ucfirst($row['status']); ?></td>
<td>
<?php echo $subject; ?>
</td>
<td> <?php echo Format::truncate($dept,30); ?></td>
<td><?php echo $phone; ?></td>
</tr>
<?php
}
} else {
echo '<tr><td colspan="7">Your query did not match any records</td></tr>';
}
?>
</tbody>
</table>
<?php
if($res && $num>0) {
echo '<div> Page:'.$pageNav->getPageLinks().' </div>';
}
?>
$limit='';
$i=0;
$q=mysql_query(...)
while($i<=mysql_num_rows($q))
{
$b=$i+5;
$limit='limit '.$i.', '.$b;
mysql_query(...$limit)
}

multiple arrays value fetching with session

Insert Is Fine But if I select this value from database All Values are fine but single values fetch array problem I don't know how to solve this task. Please Update this code asap.
This Is Insert Code .....
<?php
if(isset($_POST['sendmessage'])){
$entermessage = $_POST['teachermessage'];
$checkbox_user = $_POST['usernameallcheckbx'];
$arr = implode(',',$checkbox_user);
//$arr2 = explode(',',$arr);
$insert = mysql_query("INSERT into usermessages(fromteacher,toparent,messages) VALUES('".$_SESSION['username']."','$arr','$entermessage')");
if($insert == 1){
echo "<h1>successful</h1>";
}
else{
echo mysql_error();
}
}
?>
<form method="post">
<div style="float:left; width:450px;"><br/><br/>Message: <br/>
<textarea style="width:400px; height:300px;" name="teachermessage"></textarea><br/>
<input type="submit" value="Send" name="sendmessage" /></div>
<div style="float:left; with:200px; padding-top:55px;">
<table>
<tr>
<?php
$select_query1 = mysql_query("SELECT * FROM register_user WHERE teacher='$teachername'");
while($chckbx=mysql_fetch_array($select_query1))
{
?>
<td><?php echo "<input type='checkbox' name='usernameallcheckbx[]' value=". $chckbx['userid']." />"; ?></td>
</tr>
<tr>
<td><?php echo $chckbx['parent_fname']." ".$chckbx['parent_lname']; ?></td>
</tr>
<?php
}
?>
</table>
</div>
</form>
And This Is Select Code....
<h2>Messages</h2>
<?php
$select_query3 = mysql_query("SELECT * FROM usermessages");
$fetch= mysql_fetch_array($select_query3);
$data=$fetch['toparent'];
$arr=explode(',',$data);
//$userids=explode(',',$data);
$sessionshow=$_SESSION['userid'];
$userids=in_array("$sessionshow",$arr);
$select_query2 = mysql_query("SELECT * FROM usermessages WHERE toparent in ('$userids')='".$_SESSION['userid']."'");
?>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<th>Teacher Name</th>
<th>Message</th>
</tr>
<?php
while($fetch_name2=mysql_fetch_array($select_query2))
{
echo "<tr>";
echo "<td>".$fetch_data=$fetch_name2['fromteacher']."</td>";
echo "<td>".$fetch_data=$fetch_name2['messages']."</td>";
echo "</tr>";
}
?>
</table>
I have only put this as an answer to show some incorrect code - remove fetch data from your loop as it doesn't do anything
while($fetch_name2=mysql_fetch_array($select_query2))
{
echo "<tr>";
echo "<td>".$fetch_name2['fromteacher']."</td>";
echo "<td>".$fetch_name2['messages']."</td>";
echo "</tr>";
}
even better is use of a HEREDOC:
while($fetch_name2=mysql_fetch_array($select_query2))
{
echo <<<EOF
<tr>
<td>{$fetch_name2['fromteacher']}</td>
<td>{$fetch_name2['messages']}</td>
</tr>
EOF;
}
I really can't figure out what you're trying to do, but maybe this is the query you want:
SELECT * FROM usermessages WHERE FIND_IN_SET('$sessionshow', toparent)
FIND_IN_SET(str, strlist) searches the comma-separated list in strlist for an element that equals str, and returns the position in the list; if it's not found it returns 0, which counts as false.
I can't see any purpose to any of the code that uses $select_query3.

Categories