I have created a php file called search.php. I want to show the result on a table
I want a table structure like this.
__________________________
| |________________|
| |________________|
| |________________|
|________|________________|
|________________|
|________________|
On the left side I want to place a picture which will be obtained from database and to the right I will place information about the student photo.
Could you write a code. Can we separate photo and the information column by a vertical line only.(if yes,HOW ?? )
<table>
<tr>
<td rowspan="4" style="border-right: 1px solid black">
<img src"whatever.png" alt="" />img
</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
</tr>
<tr>
<td>3</td>
</tr>
<tr>
<td>4</td>
</tr>
<tr>
<td rowspan="2">
</td>
<td>5</td>
</tr>
<tr>
<td>6</td>
</tr>
</table>
but really: learn html an get used to the boxed model, that is: use divs
<?php
$sql = "Select FROM * `yourtablename` where `id` = 'theidofthestudent'";
if(!mysql_query($sql)){
die(mysql_error());
} else {
echo "<table border="1px" style="text-align:center;" align="justify">";
echo "<th>Photo of student</th>";
echo "<th>Name of the student</th>";
echo "<th>Student Detials</th>";
while($row = mysql_fetch_array($sql)){
echo "<tr>";
echo "<td style="float:left;">' . $row['student_pic'] . "</td>";
echo '<td style="float:right;">' . $row['student_name'] . "</td>";
echo '<td style="float:right;">' . $row['student_details'] . "</td>";
echo "</tr>"
} echo "</table>";
}
?>
Related
First of all. I apologize for the poor English. I'm also sorry for the novice level of this question.
I would like to put my SQL results in a table, and add a new row for every result.
if(mysql_num_rows($raw_results) > 0){
while($results = mysql_fetch_array($raw_results)){
echo "<p><b>".$results['FNAME']."</b> " .$results['LNAME']." ".$results['AGE']."</p>";
}
}
So I would like [FNAME] in a own TD, [LNAME] in it's on TD and the same with [AGE].
Thank you in advance!
Just put <tr> around each row of data, <td> around each column, and put everything inside <table>.
if (mysql_num_rows($raw_results) > 0) {
echo "<table><tr><th>First Name</th><th>LAst Name</th><th>Age</th></tr>";
while ($results = mysql_fetch_assoc($raw_results) {
echo "<tr><td>{$results['FNAME']}</td><td>{$results['LNAME']}</td><td>{$results['AGE']}</td></tr>";
}
echo "</table>";
}
use this code :
<table>
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<?php
if(mysql_num_rows($raw_results) > 0){
while($results = mysql_fetch_array($raw_results)){
echo "<tr><td>" . $results['FNAME'] . "</td><td>" . $results['LNAME'] . "</td><td>" .$results['AGE']."</td></tr>";
}
}
?>
</tbody>
</table>
This is my code the table appears up with the header and everything but the row with the td tag data shows nothing at all
echo "<p></p>";
//display name of the page and some random text
echo "<h2>".$pagename."</h2>";
if($_POST['h_prodid'] > 0){
$newprodid = $_POST['h_prodid'];
$reququantity =$_POST['quantity'];
$_SESSION['basket'][$newprodid]=$reququantity;
echo "<p>Your basket has been updated</p>";
} else {
echo "<p>Existing basket</p>";
}
echo "<table border = '1'>
<tr><th>Product Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Subtotal</th>
</tr>";
echo "<td>".$reququantity."</td>";
echo "</table>";
The reason your data is NOT displaying in the html is because it is NOT in a tr ( table row ) - simply a floating table cell
if( $_SERVER['REQUEST_METHOD']=='POST' ){
echo "<h2>".$pagename."</h2>";
if( isset( $_POST['h_prodid'],$_POST['quantity'] ) ){
if( $_POST['h_prodid'] > 0 ){
$newprodid = $_POST['h_prodid'];
$reququantity =$_POST['quantity'];
$_SESSION['basket'][$newprodid]=$reququantity;
echo "<p>Your basket has been updated</p>";
}else{
echo "<p>Existing basket</p>";
}
echo "
<table border = '1'>
<tr>
<th>Product Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Subtotal</th>
</tr>
<tr>
<td> </td>
<td> </td>
<td>{$reququantity}</td>
<td> </td>
</tr>
</table>";
}
}
I have a bootstrap table which has pairs of rows appear like the following:
There is a button generated at the end of the first row. Is there way to make it appear so its BETWEEN the two rows (i.e. sat on the line that is dividing the two rows) instead of it being in the first row only? I am using the Boostrap table class 'table' so the styling is automatically applied.
The table is generated via PHP script, here is the snippet:
$table = "<table class='table'>";
$table .= "<thead><tr><th>Departing Station</th><th>Depart Time</th><th>Destination</th><th>Arrival Time</th><th>Route</th></tr></thead>";
$table .= "<tbody>";
foreach ($printable_results as $result){
$journey1 = $result['journey1']['journey_id'];
$journey2 = $result['journey2']['journey_id'];
$table .= "<tr style='background-color:#F9F9F9;'>
<td>" . $result['journey1']['start_station'] . "</td>
<td>" . $result['journey1']['depart_time'] . "</td>
<td>" . $result['journey1']['end_station'] . "</td>
<td>" . $result['journey1']['arrive_time'] . "</td>
<td>
<a href='index.php?action=route_changeover&journey1_id=". $journey1 . "&journey2_id=". $journey2 . "'>
<input class='btn btn-success' type='submit' value='Full Route >'>
</a>
</td>
</tr>";
$table .= "<tr style='background-color:#F9F9F9;'>
<td>" . $result['journey2']['start_station'] . "</td>
<td>" . $result['journey2']['depart_time'] . "</td>
<td>" . $result['journey2']['end_station'] . "</td>
<td>" . $result['journey2']['arrive_time'] . "</td>
<td></td>
</tr>";
$table .= "<tr><td colspan='4'></td></tr>";
}
$table .= "</tbody></table>";
echo $table;
You can use row span to make it happen :)
.table>tbody>tr>td.route-wrap {
vertical-align: middle;
text-align: center;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<table class="table">
<thead>
<tr>
<th>Departing Station</th>
<th>Depart Time</th>
<th>Destination</th>
<th>Arrival Time</th>
<th>Route</th>
</tr>
</thead>
<tbody>
<tr>
<td>Text</td>
<td>Text</td>
<td>Text</td>
<td>Text</td>
<td class="route-wrap" rowspan="2">
<input class='btn btn-success' type='submit' value='Full Route >'>
</td>
</tr>
<tr>
<td>Text</td>
<td>Text</td>
<td>Text</td>
<td>Text</td>
</tr>
</tbody>
</table>
I have a very basic and simple script that should display records from my database. The problem: it doesn't show all the records. I've tried it even with the most simple mysql
($sql="SELECT * FROM $tbl_name";) but still some records are missing (mostly the first of the list that isn't shown).
So here is my code (it's all on 1 page):
<?php
$host="localhost";
$username="***";
$password="***";
$db_name="***";
$tbl_name="***";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name WHERE rowNameOne >= 0.01 AND rowNameTwo='2013'";
if ($_GET['sort'] == 'one')
{
$sql .= " ORDER BY one ASC";
}
elseif ($_GET['sort'] == 'two')
{
$sql .= " ORDER BY two ASC";
}
elseif ($_GET['sort'] == 'three')
{
$sql .= " ORDER BY three ASC";
}
elseif($_GET['sort'] == 'four')
{
$sql .= " ORDER BY four ASC";
}
elseif($_GET['sort'] == 'five')
{
$sql .= " ORDER BY five ASC";
}
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>
<body onload="parent.alertsize(document.body.scrollHeight);">
<br />
<table cellspacing="0" cellpadding="0" align="center">
<tr>
<td valign="top" colspan="5">
<font>Titel</font>
</td>
<tr>
<td>Titel one</td>
<td>Titel two</td>
<td>Titel three</td>
<td>Titel four</td>
<td>Titel five</td>
</tr>
<tr>
<td colspan="5" class="noBorder">
<?php
while($rows=mysql_fetch_array($result)){
?>
<a href="pageName.php?id=<? echo $rows['id']; ?>" >
<table width="100%">
<tr>
<td><? echo $rows['rowNameOne']; ?></td>
<td><? echo $rows['rowNameTwo']; ?></td>
<td><? echo $rows['rowNameThree']; ?></td>
<td><? echo $rows['rowNameFour']; ?></td>
<td><? echo $rows['rowNameFive']; ?></td>
</tr>
</table>
<input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>">
<?php
}
?>
</a>
</td>
</tr>
</table>
It's a very basic code, easy as can be I would say, but still it's missing records, not displaying everything that's in the database. What am I doing wrong?
Thanks for the help!
Before you start the loop, you do this:
$rows=mysql_fetch_array($result);
Then the loop condition is:
while($rows=mysql_fetch_array($result)){
So the first result is never shown. I would advice to remove the first statement, since you're not using its results between that statement and the loop.
On a related note, please consider moving to PDO or mysqli.
I am not a trained programmer. Whatever I learned is by myself from the net. Please excuse if you find my code and question very amateurish.
I am trying to call matches of buyers against sellers data from the database and automatically mail them their matches.
When I run this code on my system with EasyPhp, it says 'Query was empty". And when I run this on my server, it says "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1 " where am I going wrong ?
<?php
include('adminmaster.htm');
Echo "<center>Mail Matching Properties</center><br><br>";
mysql_connect("localhost", "username","password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
$query= 'SELECT*FROM clientdata WHERE email != " " AND Transaction="Buyer"';
$result=mysql_query($query);
echo mysql_error();
if (!$result){ die("No Buy results");}
$matchrows=mysql_num_rows($result);
if($matchrows==0){ die("No Buy results");}
while($info = mysql_fetch_array($result))
$Price1= $info['Price']+($info['Price']*10/100);
$Price2 = $info['Price']-($info['Price']*10/100);
$una=$info['username'];
$query2='SELECT*FROM clientdata WHERE email!=" " AND Transaction="Seller"';
$result2=mysql_query($query2);
echo mysql_error();
$matchrows2=mysql_num_rows($result2);
if($matchrows2==0){ die("Sell Data Not Found");}
if(!$result2)
{die("Sell Data Not Found");}
while($info2=mysql_fetch_array($result2))
{
if ($info['Detail']==$info2['Detail'])
{
if ($info['Location']==$info2['Location'])
{
if ($Price1 >= $info2['Price'])
{
if ($Price2 <= $info2['Price'])
{
if ($info['username']!=$info2['username'])
{
echo mysql_error();
echo "<table width=600 border = 1 style='text-align:left';>
<tr>
<td><b>Clients</b></td>
<td><b><font color='maroon'>BUYER</font></b></td>
<td><b><font color='maroon'>SELLER</font></b></td>
</tr>
<tr>
<td><b>Date Posted:</b></td>
<td>$info[Date]</td>
<td>$info2[Date]</td>
</tr>
<tr>
<td><b>Title:</b></td>
<td>$info[propheading]</td>
<td>$info2[propheading]</td>
</tr>
<tr>
<td><b>Transaction:</b></td>
<td>$info[Transaction]</td>
<td>$info2[Transaction]</td>
</tr>
<tr>
<td style='background-color:lightgrey'><b>Detail:</b></td>
<td style='background-color:lightgrey'>$info[Detail]</td>
<td style='background-color:lightgrey'>$info2[Detail]</td>
</tr>
<tr>
<td style='background-color:lightgrey'><b>Price:</b></td>
<td style='background-color:lightgrey'>$info[Price]</td>
<td style='background-color:lightgrey'>$info2[Price]</td>
</tr>
<tr>
<td><b>Additional Data:</b></td>
<td>$info[AdditionalData]</td>
<td>$info2[AdditionalData]</td>
</tr>
<tr>
<td><b>Location:</b></td>
<td>$info[Location]</td>
<td>$info2[Location]</td>
</tr>
<tr>
<td><b>Agent/Individual:</b></td>
<td>$info[Agent_Ind]</td>
<td>$info2[Agent_Ind]</td>
</tr>
<tr>
<td><b>Name:</b></td>
<td>$info[Title] $info[firstname] $info[lastname]</td>
<td>$info2[Title] $info2[firstname] $info2[lastname]</td>
</tr>
<tr>
<td><b>Phone:</b></td>
<td>$info[Phone]</td>
<td>$info2[Phone]</td>
</tr>
<tr>
<td><b>Email:</b></td>
<td>$info[Email]</td>
<td>$info2[Email]</td></tr>
</table>";
$tomail=$info2['Email'];
if ($tomail=="anitgopinath#gmail.com"|$tomail=="anit#landshoppe.com"|$tomail=="info#landshoppe.com") {continue;}
$headers ="From:info#landshoppe.com"."\r\n";
$headers .='Bcc:anit#landshoppe.com'."\n";
$headers .= 'MIME-Version: 1.0'."\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
$subject ="You have a Property Match !";
$message="<html></head><body>
<table width=600 border = 1 style='text-align:left';>
<caption><b><font color='maroon'>YOUR PROPERTY MATCH!</font></b></caption>
<tr>
<td><b>Date Posted:</b></td>
<td>$info[Date]</td>
</tr>
<tr>
<td><b>Title:</b></td>
<td>$info[propheading]</td>
</tr>
<tr>
<td><b>Transaction:</b></td>
<td>$info[Transaction]</td>
</tr>
<tr>
<td style='background-color:lightgrey'><b>Detail:</b></td>
<td style='background-color:lightgrey'>$info[Detail]</td>
</tr>
<tr>
<td style='background-color:lightgrey'><b>Price:</b></td>
<td style='background-color:lightgrey'>$info[Price]</td>
</tr>
<tr><td><b>Additional Data:</b></td><td>$info[AdditionalData]</td></tr>
<tr><td><b>Location:</b></td><td>$info[Location]</td></tr>
<tr><td><b>Agent/Individual:</b></td><td>$info[Agent_Ind]</td></tr>
<tr><td><b>Name:</b></td><td>$info[Title] $info[firstname] $info[lastname]</td></tr>
<tr><td><b>Phone:</b></td><td>$info[Phone]</td></tr>
<tr><td><b>Email:</b></td><td>$info[Email]</td></tr>
</table></body><html>";
echo $tomail."<br>";
echo "$message"."<br>";
$mailresult=mysql_query(mail($tomail,$subject,$message,$headers));
if ($mailresult){echo "Mailed<br>";}else{echo "Not Mailed !<br>";}
echo "**********************************Seller Match**************************************************<br>";
$tomail2=$info['Email'];
if ($tomail2=="anitgopinath#gmail.com"|$tomail2=="anit#landshoppe.com"|$tomail2=="info#landshoppe.com"){continue;}
$headers ="From:info#landshoppe.com"."\r\n";
$headers .='Bcc:anit#landshoppe.com'."\n";
$headers .= 'MIME-Version: 1.0'."\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
$subject ="You have a Property Match !";
$message="<html></head><body>
<table width=600 border = 1 style='text-align:left';>
<caption><b><font color='maroon'>YOUR PROPERTY MATCH!</font></b></caption>
<tr>
<td><b>Date Posted:</b></td>
<td>$info2[Date]</td>
</tr>
<tr>
<td><b>Title:</b></td>
<td>$info2[propheading]</td>
</tr>
<tr>
<td><b>Transaction:</b></td>
<td>$info2[Transaction]</td>
</tr>
<tr>
<td style='background-color:lightgrey'><b>Detail:</b></td>
<td style='background-color:lightgrey'>$info2[Detail]</td>
</tr>
<tr>
<td style='background-color:lightgrey'><b>Price:</b></td>
<td style='background-color:lightgrey'>$info2[Price]</td>
</tr>
<tr>
<td><b>Additional Data:</b></td>
<td>$info2[AdditionalData]</td>
</tr>
<tr>
<td><b>Location:</b></td>
<td>$info2[Location]</td>
</tr>
<tr>
<td><b>Agent/Individual:</b></td>
<td>$info2[Agent_Ind]</td>
</tr>
<tr>
<td><b>Name:</b></td>
<td>$info2[Title] $info2[firstname] $info2[lastname]</td>
</tr>
<tr>
<td><b>Phone:</b></td>
<td>$info2[Phone]</td>
</tr>
<tr>
<td><b>Email:</b></td>
<td>$info2[Email]</td>
</tr>
</table></body><html>";
echo $tomail2."<br>";
echo "$message"."<br>";
$mailresult2=mysql_query(mail($tomail2,$subject,$message,$headers));
if ($mailresult2){echo "Mailed<br>";}else{echo "Not Mailed !<br>";}
echo "**********************************Buyer Match**************************************************<br>";
}
}
}
}
}
}
}
?>
First of all, when specifying string literals within SQL request you should use single qoutes:
$query= "SELECT*FROM clientdata WHERE email != ' ' AND Transaction='Buyer'";
Don't want to sound rude, but you better redesign your code, it's a mess right now. Start with a simple 'divide and conquer' method: mark each block of code that does ONE and only ONE thing - and separate into a single function (leaving only its call in the main script). You'll instantly notice the difference it'll make in both reading and updating your code.
The error you spoke about is caused by this line:
$mailresult=mysql_query(mail($tomail,$subject,$message,$headers));
... as the result of mail function is boolean. And when converted into string by mysql_query, it's either an empty string or '1'; both of them, of course, are not valid queries. If you need to check the result, it's just...
$mailresult=mail($tomail,$subject,$message,$headers);
And again, the error itself is simple - but it's hidden in your code so good that five or more SO users failed to find it. ) That's why the code needs restructuring.