I have been trying to work this out for hours and I’m not sure how to achieve the correct result, hopefully someone will be able to help me.
I have the below code that will echo the result is a table vertically, but I want the cells next to each other horizontally, how can I achieve this?
<?php
echo "<table border='1' cellpadding='1' width='100%' bordercolor='000099'border='solid'>
";
echo '<div style="width:100%;">';
while($row = mysql_fetch_array($boxlink))
echo "<tr>";
{
echo "<td>" . $row['page_page_title'] . "</td>";
}
echo "</tr>";
echo "</table>";
echo '</div>';
?>
Brill that worked thanks a lot, why is it the small things can cause such a problem!
Move your tr tags outside of the loop. Each time a tr tag is seen it makes another row.
try this:
<?php
echo '<div style="width:100%;">';
echo "<table border='1' cellpadding='1' width='100%' bordercolor='000099'border='solid'>
";
echo "<tr>";
while($row = mysql_fetch_array($boxlink))
{
echo "<td>" . $row['page_page_title'] . "</td>";
}
echo "</tr>";
echo "</table>";
echo '</div>';
?>
Related
I use this while loop to display events from facebook. I want to add an href link in each record that will open a new tab displaying only this event. I have created links for each record but I can't understand how I can make the link to lead to that event.
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<table class='table table-hover table-responsive table-bordered'>";
echo "<tr>";
echo "<td rowspan='6' style='width:20em;'>";
echo "<img src=". $row["COVER_PHOTO"]." width='200px' />";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td style='width:15em;'>What:</td>";
echo "<td><b>". $row["NAME"]."</b></td>";
echo "</tr>";
//owner
echo "<tr>";
echo "<td>Who:</td>";
echo "<td>". $row["OWNER"]."</td>";
echo "</tr>";
echo "<tr>";
echo "<td>What kind:</td>";
echo "<td>". $row["PAGE_CAT"]."</td>";
echo "</tr>";
echo "<tr>";
echo "<td>When:</td>";
echo "<td>". $row["START_DATE"]." at ". $row["START_TIME"]."</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Where:</td>";
echo "<td>". $row["PLACE"]."</td>";
echo "</tr>";
echo "<tr>";
echo "<td>";
echo "<a href='view.php?more=". $row["EVENT_ID"]."' target='_blank' <?php echo >Λεπτομέρειες</a>";
echo "<tr>";
echo "<td>Description:</td>";
echo "<td>". $row["DESCRIPTION"]."</td>";
echo "</tr>";
Your code for this page is just fine. Now to display each individual event in the view.php file, you will need to access the data (in your case the event ID, stored in more variable) sent via GET method in the view.php page, as thus:
view.php
<?php
if(isset($_GET['more']))
{
$more = $_GET['more'];
}
?>
The value of the more variable sent via the URL will now be saved in the $more PHP variable. For example, if the page called is view.php?view=22, the $more variable will have the value of 22.
You can now use this $more variable - which stores the event ID - to fetch whatever other detail you require.
echo "<a href='view.php?more=". $row["EVENT_ID"]."' target='_blank'> Λεπτομέρειες</a>";
This is my code (horrible one):
<?php
include 'connect/con.php';
$result = mysqli_query($con,"SELECT id, vidTitle FROM newsvid");
$result1 = mysqli_query($con,"SELECT imgCover, vidSD FROM newsvid");
$result2 = mysqli_query($con,"SELECT published FROM newsvid");
echo "<table width=\"600\" border=\"1\"><tbody>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo '<td width=\"10%\">'.$row['id'].'</td>';
echo "<td width=\"90%\">" . $row['vidTitle'] . "</td>";
echo "</tr>";
}
echo "</tbody></table>";
echo "<table width=\"600\" border=\"1\"><tbody>";
while($row = mysqli_fetch_array($result1)) {
echo "<tr>";
echo "<td width=\"40%\">" . $row['imgCover'] . "</td>";
echo "<td width=\"60%\">" . $row['vidSD'] . "</td>";
echo "</tr>";
}
echo "</tbody></table>";
echo "<table width=\"600\" border=\"1\"><tbody>";
while($row = mysqli_fetch_array($result2)) {
echo "<tr>";
echo "<td >" . $row['published'] . "</td>";
echo "</tr>";
}
echo "</tbody></table>";
mysqli_close($con);
?>
</body>
</html>
The question is how to show data from database in this layout:
--------------------------------
-id----------vidTitle-----------
--------------------------------
-imgCover------vidSD------------
--------------------------------
----------published-------------
So every time I will add more data , another block like I showed before will add up under existing one.
........................................................................................
There's no need to write 3 queries. You could do that with only one select, and then put all the echos inside a while. That way you're writing, it would run all the ids and titles first, then it would put a table after the table, with cover and vidSD.
Try to make a single query:
SELECT id, vidTitle, imgCover, vidSD, published FROM newsvid
That way you will have, on each row returned from database, all the information about the same row.
Now, running a while is the same as you're doing, just adapting some HTML:
echo "<table width='600' border='1'><tbody>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo '<td width=\"10%\">'.$row['id'].'</td>';
echo "<td width=\"90%\">" . $row['vidTitle'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td width=\"40%\">" . $row['imgCover'] . "</td>";
echo "<td width=\"60%\">" . $row['vidSD'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan='2'>" . $row['published'] . "</td>";
echo "</tr>";
}
echo "</tbody></table>";
You may want to order it too. Adding ORDER BY id DESC, would do that.
i'm trying to do a table with php and mysqli and i want to see the results in the html. For some reason it is not working
Thanks in advance.
Here is my code:
<?php
require 'connect.php';
$link->query("SELECT nome, id_utilizador FROM utilizador");
echo "NSA INFORMATION";
echo "<table border='1' cellpadding='2' cellspacing='2'";
echo "<tr><td>ID</td><td>NAME</td>";
while ($row = mysqli_fetch_array($query)) {
echo "<tr>";
echo "<td>" . $row["nome"] . "</td>";
echo "<td>" . $row["id_utilizador"] . "</td>";
echo "</tr>";
}
?>
echo "</table>"; after the while loop. In your code outputted html is not valid as table element has no required closing tag. You also forgot the closing tag for tr before the while loop and close the opening tag for table.
I am trying to make a table in PHP.
All things are fine but all the rows are printed in same line.
How to print new line after each row in table? But in html there is no need to write extra code for new line why it is showing not a new line with PHP?
Here is that part of code:
<div class="contest-table" id="contest-table">
<table class="contest-details" id="contest-details">
<tr>
<th>CODE</th>
<th>NAME</th>
<th>START</th>
<th>END</th>
</tr>
<?php
//Show contest detials -> Contest Code|Contest Name |Start Date | End Date
$con=mysqli_connect("localhost","root","chandan","judge");
$result=mysqli_query($con,"SELECT * FROM judge_contest ");
echo "<tr>";
while($row = mysqli_fetch_array($result))
{
$contest_code=$row['contest_code'];
$contest_name=$row['contest_name'];
$contest_start_date=$row['start_date'];
$contest_end_date=$row['end_date'];
echo "<td>";
echo " $contest_code ";
echo "</td>";
echo "<td>";
echo " $contest_name ";
echo "</td>";
echo "<td>";
echo $contest_start_date;
echo "</td>";
echo "<td>";
echo $contest_end_date;
echo "</td>";
}
echo "</tr>";
?>
</table>
</div>
The problem is obvious, because you have put the statement echo "<tr>" and echo "</tr>" outside the while loop. You should put these two statement into the while loop.
echo '<tr>'
and
echo '</tr>'
should be inside the wile loop
I need some help regarding pagination, the problem is that I want to show my database records first time on button click with pagination but every time I click on pagination link it requires click on button
Here is my code I know I am making some mistake please check and kindly do me a favor by correcting my mistake ..
if (isset($_POST["search"])){
$result=mysql_query("select count(*) from reg_phone");
$row=mysql_fetch_row($result);
$tr=$row[0];
$rpp=4;
$pn=1;
if(isset($_GET['pn']))
{
$pn=$_GET['pn'];
}
$tp=($tr/$rpp);
if($tr/$rpp>=0)
{
$tp++;
}
$from=(($pn-1)*$rpp)+1;
$to=($pn)*($rpp);
$show = "SELECT * FROM reg_phone where Id between $from and $to";
$rs = mysql_query($show) or die(mysql_error());
#****results in Grid****
echo "<table width='100%' border='1' cellpadding='2' border-color='#000' id='tbl'>";
echo "<tr>";
echo "<td style='background: white;'><b>IMEI #</td>";
echo "<td style='background: white;'><b>Phone #</td>";
echo "<td style='background: white;'><b>From Date</td>";
echo "<td style='background: white;'><b>Status</td>";
echo "</tr>";
$rowID = 1;
while ($row = mysql_fetch_array($rs)) {
echo "<tr>";
echo "<td id='imeinum" . $rowID . "'>$row[imei]</td>";
echo "<td id='phnum" . $rowID . "'>$row[phonenum]</td>";
echo "<td id='datepicker" . $rowID . "'>$row[fdate]</td>";
echo "<td id='rad" . $rowID . "'>$row[status]</td>";
echo "</tr>";
$rowID++;
}
echo "</table>";
echo "<ul id='pages'>";
for($i=1;$i<=$tp;$i++)
{
echo "<li><a href='phonereg.php?pn=$i'>$i</a></li>";
}
echo "</ul>";
#**********************
mysql_free_result($rs);
}
http://www.hscripts.com/scripts/jquery/pagination.php
the script here is really helpful to me. Exactly what i want to do. hope anyone one in future will need this.
thanks all for suggestions.
Regards.
BKay