How to show images from my sql to this table? in php - php

i have a pagination code in php ,i tried to show images post_images from my sql to this table in my code but nothing happen ,i tried echo '<img src= images/$post_image />';
,can you tell me please what i can do ?
my code :
<table height="200px" style="border:3px black solid;border-radius:5px" width="550px">
<tr>
<th colspan="2" height="40px" style="border-bottom:3px black solid">posts in this site</th>
</tr>
<?php
$link=mysql_connect("localhost","username","pass");
mysql_select_db("itstuff_paging",$link);
$q="select count(*) \"total\" from posts";
$ros=mysql_query($q,$link) or die(mysql_error());
$row=mysql_fetch_array($ros);
$total=$row['total'];
$dis=4;
$total_page=ceil($total/$dis);
$page_cur=(isset($_GET['page']))?$_GET['page']:1;
$k=($page_cur-1)*$dis;
$q="select * from posts limit $k,$dis";
$ros=mysql_query($q,$link);
while($row=mysql_fetch_array($ros))
{
echo '<tr>';
echo '<td width="10px" style="border-bottom:1px #a1a1a1 solid">'.$row
['post_id'].'.';
echo '<br/>';
echo '<td style="border-bottom:1px #a1a1a1 solid">'.$row['post_title'];
echo '<br/>';
echo ($row['post_content']);
echo '<br/>';
echo '<img src= images/$post_image />';
echo '</tr>';
}
echo '</table>';
echo '<br/>';
if($page_cur>1)
{
echo '<a href="index.php?page='.($page_cur-1).'"
style="cursor:pointer;color:green;" ><input style="cursor:pointer;background-
color:green;border:1px black solid;border-radius:5px;width:120px;height:30px;color:white;font-
size:15px;font-weight:bold;" type="button" value=" Previous "></a>';
}
else
{
echo '<input style="background-color:green;border:1px black solid;border-
radius:5px;width:120px;height:30px;color:black;font-size:15px;font-weight:bold;" type="button"
value=" Previous ">';
}
for($i=1;$i<$total_page;$i++)
{
if($page_cur==$i)
{
echo ' <input style="background-color:green;border:2px black
solid;border-radius:5px;width:30px;height:30px;color:black;font-size:15px;font-weight:bold;"
type="button" value="'.$i.'"> ';
}
else
{
echo '<a href="index.php?page='.$i.'"> <input style="cursor:pointer;background-
color:green;border:1px black solid;border-radius:5px;width:30px;height:30px;color:white;font-
size:15px;font-weight:bold;" type="button" value="'.$i.'"> </a>';
}
}
if($page_cur<$total_page)
{
echo '<a href="index.php?page='.($page_cur+1).'"><input
style="cursor:pointer;background-color:green;border:1px black solid;border-
radius:5px;width:90px;height:30px;color:white;font-size:15px;font-weight:bold;" type="button"
value=" Next "></a>';
}
else
{
echo '<input style="background-color:green;border:1px black solid;border-
radius:5px;width:90px;height:30px;color:black;font-size:15px;font-weight:bold;" type="button"
value=" Next ">';
}
?>
</table>

You never define $post_image before you use it, so you're generating <img src="" />. Perhaps you meant:
echo "<img src=images/{$row['post_image']} />";
instead?

Your code is malformed. Please try:
echo '<img src="images/'.$post_image.'" />';

Related

How to add images from database with caption

What I want to do is that, It should display 3 images on every line and along with their captions.And their could be many rows. How can do that ? here is my code..
while($info=mysql_fetch_array($query))
{
$image=$info['image'];
$cap=$info['caption'];
echo '<img src="'.$image.'" />';
echo $cap;
}
I got the answer.
I don't know hows its working . But it is ....
<table>
<?php
$i=1;
$query=mysql_query("SELECT * FROM publish");
while($info=mysql_fetch_array($query))
{
$inq=$info['ref'];
$imagesrc=$info['image'];
$ti=$info['title'];
if($i%3==1 || $info['id']==1 )
{
echo "<tr></tr>";
}
?>
<td>
<a href="movieview.php?ref=<?php echo $info['ref']; ?>">
<?php
echo '<img src="admin/'.$imagesrc.'" style="width:138px;height:200px;" />';
echo '</a><br />';
echo $ti;
$i++;
}
?>
</td>
</table>

How to put mysql data into popup window?

I have a web page with images and when user clicks on any of the image, it has to derive data of that particular image from MYSQL database. What I am doing is using a simple JavaScript popup and putting the data from database. However I am just getting the first item from database on all images.
This is the code:
$files = glob("admin/images/paintings/*.*");
echo '<div id="painting"><table border="0" style="width:590px;">';
$colCnt=0;
$i = 0;
while($row = mysql_fetch_array($result))
{
if ($colCnt%4==0)
echo '<tr>';
echo '<td width="25%" style="font-size:8.5px; font-family:arial">';
echo($i);
$num = $files[$i];
echo '<img id="indPainting" src="'.$num.'" align="absmiddle" /> <br> <div id="paintingName">';
print $row['name'];
echo '<div id="openModal" class="modalWindow">
<div>
<p>This is a sample modal window that can be created using CSS3 and HTML5.'.$row['name'].'</p>
Ok
</div>
</div>';
echo '</td>';
$colCnt++;
if ($colCnt==4)
{
echo '</tr>';
$colCnt=0;
}
$i++;
}
mysql_close($con);
include 'footer.php';
?>
$row['name'] is just giving out the first name as it is in a while loop. I am not being able to get other names for other images. How can this be done. Any help would be appreciated.
Does one iteration in your while fetch single image data? And what I can understand according to your code is that you are displaying 4 image in a row.
Can you please format your code a bit..its looking too ugly.
I need to know which statement is calling your modal window.
<?php
$files = glob("admin/images/paintings/*.*");
echo '<div id="painting"><table border="0" style="width:590px;">';
$colCnt=0;
$i = 0;
echo '<tr>';
while($row = mysql_fetch_array($result))
{
$num = $files[$i];
echo '<td width="25%" style="font-size:8.5px; font-family:arial">';
echo '<img id="indPainting" src="'.$num.'" align="absmiddle" /> <br>
<div id="paintingName">';
print $row['name'];
echo '<div id="openModal" class="modalWindow"><div><p>This is a sample modal window that can be created using CSS3 and HTML5.'.$row['name'].'</p>Ok</div>
</div></td>';
$colCnt++;
if ($colCnt % 4 == 0)
{
echo '</tr>';
$colCnt=0;
}
$i++;
}
mysql_close($con);
include 'footer.php';
?>
Try this.
Also see how beautiful the code looks if its properly formatted..
try this
<?php
$files = glob("admin/images/paintings/*.*");
echo '<div id="painting"><table border="0" style="width:590px;">';
$colCnt=4;
while($row = mysql_fetch_array($result))
{
for ($i = 0; $i < $colCnt; $i++) {
echo '<tr>';
echo '<td width="25%" style="font-size:8.5px; font-family:arial">';
echo($i);
$num = $files[$i];
echo '<img id="indPainting" src="'.$num.'" align="absmiddle" /> <br> <div id="paintingName">';
print $row['name'];
echo '<div id="openModal" class="modalWindow">
<div>
<p>This is a sample modal window that can be created using CSS3 and HTML5.'.$row['name'].'</p>
Ok
</div>
</div>';
echo '</td>';
}
if ($colCnt==4)
{
echo '</tr>';
$colCnt=0;
}
}
mysql_close($con);
include 'footer.php';
?>

how to prompt search query into a dynamic iframe

hi there i am creating a data grid which loads data from the database and i had even created a search box which prompts the search queries when a user inputs a value into it but now i want to show my search query into the same iframe which is loading the file of data table and when the search box is empty it should show the data table and if a user enters a query it should load the query into it here is my script
<div style="float: right; border: 1px; padding-right: 20px;">
<div class="search">
<input type="text" name="s" maxlength="64" placeholder="Search" id="inputString" onkeyup="lookup(this.value);" />
<img src="images/srch.png" id="srch_btn"/>
</div>
</div>
</div>
</div>
</div>
<table border="0" width="100%" class="myclass" height="30px">
<tr>
<td width="80px" align="center"><font color="black" size="3px">Sr No.</font></td>
<td width="80px" align="center"><font color="black" size="3px">Br No.</font></td>
<td width="180px" align="center"><font color="black" size="3px">Name</font></td>
<td width="200px" align="center"><font color="black" size="3px">Address</font></td>
<td width="120px" align="center"><font color="black" size="3px">City</font></td>
<td width="80px" align="center"><font color="black" size="3px">Pin</font></td>
<td width="80px" align="center"><font color="black" size="3px">Mobile</font></td>
<td width="120px" align="center"><font color="black" size="3px">Email</font></td>
<td width="80px" class="myclass" align="center"><font color="black" size="3px">Actions</font></td>
</tr>
</table>
<div id="suggestions">/****file that shows the search queries**/
<iframe src="record.php" width="1150" height="900" frameBorder="0"></iframe> /** File that loads the data table**/
</div>
here is my search script
$db = new mysqli('localhost', 'root', '', 'mdb');
if(!$db) {
// Show error if we cannot connect.
echo 'ERROR: Could not connect to the database.';
} else {
// Is there a posted query string?
if(isset($_POST['queryString'])) {
$queryString = $db->real_escape_string($_POST['queryString']);
if(strlen($queryString) >0) {
$query = $db->query("SELECT * FROM mdb WHERE (`name` LIKE '%" . $queryString . "%') OR (grno LIKE '%". $queryString ."%')
OR (`address` LIKE '%". $queryString ."%') OR (`city` LIKE '%". $queryString ."%') OR (pin LIKE '%". $queryString ."%')
OR (mobile LIKE '%". $queryString ."%') OR (`email` LIKE'%". $queryString ."%') ORDER BY vouchno LIMIT 8");
if($query) {
echo "<table width='100%'>";
echo "<tr>";
echo "<th align=left>Name</th>";
echo "<th align=left>Address</th>";
echo "<th align=left>City</th>";
echo "<th align=left>Pin</th>";
echo "<th align=right>Mobile</th>";
echo "<th align=left>Email</th>";
echo "</tr>";
while ($result = $query ->fetch_object()) {
echo "<tr>";
echo "<td><span class=\"category\">$result->name</span></td>";
echo "<td>$result->address</td>";
echo "<td>$result->city</td>";
echo "<td>$result->pin</td>";
echo "<td align=right>$result->mobile</td>";
echo "<td>$result->email</td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan=9>";
echo "<hr/>";
echo "</td>";
echo "<tr>";
$name = $result->name;
if(strlen($name) > 35) {
$name = substr($name, 0, 35) . "...";
}
$description = $result->address;
if(strlen($description) > 80) {
$description = substr($description, 0, 80) . "...";
}
}
echo "</table>";
echo '<span class="seperator"><strong>No Further Records Found</strong> </span><br class="break" />';
} else {
echo 'ERROR: There was a problem with the query.';
}
} else {
echo "record.php";
}
} else {
echo 'There should be no direct access to this script!';
}
}
I think now AJAX can help you I mean. why you don't do somthing like this instead of iframe?
check this
$('#div').load('someFile.php','params');
and for scrolling the div use this in CSS
CSS
#div{
width:500px;
height:300px;
overflow:scroll;
}
here the jsfiddle.

What's wrong with this php-generated table?

I am trying to make a table via PHP, but when I load this, it displays it like this..
The code:
<table border="1" cellpadding="5">
<?php
while($test= mysql_fetch_assoc($countquery)){
echo '<tr><td>';
echo $test["count"];
echo 'x</td>';
};
while($row=mysql_fetch_array($topresult)) {
echo '<td width="150">';
echo $row["productnaam"];
echo '</td><td width="100" style="text-align:center;">€ ';
echo $row["prijs"];
echo '</td><td width="50" style="text-align:center;">';
echo '<a style="text-decoration:none;color:red;" href="#"><img width="25" src="trash.png"></a>';
echo '</td></tr>';
};
?>
</table>
My goal is to display a table of 4 columns by 3 rows..
EDIT:
Found it already, it makes a new <tr> tag everytime the first while is performed.
The block :
while($test= mysql_fetch_assoc($countquery)){
echo '<tr><td>';
echo $test["count"];
echo 'x</td>';
};
will create 3 cells 1x, 1x, 2x first,
next the block:
while($row=mysql_fetch_array($topresult)) {
echo '<td width="150">';
echo $row["productnaam"];
echo '</td><td width="100" style="text-align:center;">€ ';
echo $row["prijs"];
echo '</td><td width="50" style="text-align:center;">';
echo '<a style="text-decoration:none;color:red;" href="#"><img width="25" src="trash.png"></a>';
echo '</td></tr>';
};
will create cells from Monitor, so the result become like this.
To fix it, you should save the result from the first while loop to an array and go through at the 2nd while loop
You are echoing nested rows.
while($test= mysql_fetch_assoc($countquery)){
echo '<tr><td>';// Here you open a row
echo $test["count"];
echo 'x</td>';//No closing of row, you close the td and open another tr on the next iteration
};

member management by admin using php

Sorry for asking an implement my feature question type question last time. I am new to Stackoverflow.com and also to php that's why.
What I was trying to ask is:
I have made a admin account. Members have registration page so a member will register. When user registers in the database table I will have a field for which 0 value will be initialised which means he is not approved. In admin account I have code to get the list of members. The code is given below:
<h2><?php echo "User list"; ?></h2>
<table border="0" cellpadding="0" cellspacing="0">
<tr bgcolor="#f87820">
<td><img src="img/blank.gif" alt="" width="10" height="25"></td>
<td class="tabhead"><img src="img/blank.gif" alt="" width="150" height="6"><br><b><?php echo "first name"; ?></b></td>
<td class="tabhead"><img src="img/blank.gif" alt="" width="150" height="6"><br><b><?php echo "lastname name"; ?></b></td>
<td class="tabhead"><img src="img/blank.gif" alt="" width="150" height="6"><br><b><?php echo "member id"; ?></b></td>
<td class="tabhead"><img src="img/blank.gif" alt="" width="50" height="6"><br><b><?php echo "delete"; ?></b></td>
<td><img src="img/blank.gif" alt="" width="10" height="25"></td>
</tr>
<?php
}
$result=mysql_query("SELECT member_id,firstname,lastname,login FROM members ORDER BY firstname");
$i = 0;
while($row = mysql_fetch_array($result)) {
if ($i > 0) {
echo "<tr valign='bottom'>";
echo "<td bgcolor='#ffffff' height='1' style='background-image:url(img/strichel.gif)' colspan='6'></td>";
echo "</tr>";
}
echo "<tr valign='middle'>";
echo "<td class='tabval'><img src='img/blank.gif' alt='' width='10' height='20'></td>";
echo "<td class='tabval'><b>".$row['lastname']."</b></td>";
echo "<td class='tabval'>".$row['firstname']." </td>";
echo "<td class='tabval'>".$row['member_id']." </td>";
echo "<td class='tabval'><a onclick=\"return </span></a></td>";
echo "<td class='tabval'></td>";
echo "</tr>";
$i++;
}
?>
</table>
in this i wanna add tho more things in the table 1 to delete a member and 2 to have approved or denied option for that i made two functiom
below code is to delete
if($_REQUEST['action']=="del")
{
$memberId = mysql_real_Escape_string($_REQUEST['member_id']);
mysql_query("DELETE FROM members WHERE member_id=$memberId");
}
below one for approving members
But my problem is I don't know how to include a button or radio button in the table which can pass value delete or approve to these functions.
Please tell me how the syntax is to add this button so that for approving I can change the value 0 that I gave in the database to 1 so that member get approved.
Try this:
echo '<td><a href="http://yourwebsite/yourscriptname.php?action=del&member_id='
. htmlspecialchars($row['member_id']) . '">Delete</a>';
if ($row['approved'] == 0) {
echo ' <a href="http://yourwebsite/yourscriptname.php?action=approve&member_id='
. htmlspecialchars($row['member_id']) . '">Approve</a>';
}
echo '</td>';
And make sure ALL of your database values are being sent to the browser in htmlspecialchars().
On the flipside,
$member_id = 0;
if (isset($_GET['member_id'])) $member_id = intval($_GET['member_id']);
$action = '';
if (isset($_GET['action'])) $action = $_GET['action'];
$sql = '';
switch($action) {
case 'approve':
$sql = "UPDATE members SET approval = 1 WHERE member_id = $member_id";
break;
case 'delete':
$sql = "DELETE FROM member WHERE member_id = $member_id";
break;
}
if (!empty($sql) && !empty($member_id)) {
// execute the sql.
}
What I would do is to set up a form inside of the table.
?> <form name="deleteUser" id="deleteUser" method="post" action="">
<input type="hidden" name="member_id" id="member_id" value="<?php echo $row['member_id'] ?>
<input type="submit" name="action" id="action" value="del" />
</form><?php
I would insert that in between your <td> tag.
<td class='tabval'>INSERT HERE</td>";

Categories