Im having a problem with my PHP search script. I'm building a social networking site where one can search for a user, an event or a club. I would like the search results to display a user avatar thumb or a default thumb if none has been uploaded.
Im testing on localhost.
User avatar's are stored in the User_Images (c:\wamp\www\NNL\User_Images)folder while the default avatar is stored in c:\wamp\www\NNL\Style\Images\default_avatar.png.
The following is my PHP code:
<?php
while ($row_user = mysql_fetch_assoc($user))
{
echo "\n<table width='500' border='0'>";
echo "\n\t<tr>";
echo "<td width='50' height='50' align='center' valign='middle'><a href='user_view.php?user_id=".$row_user['user_id']."'>
<img src=User_Images/$row_user[picture_thumb_url] !=''? $row_user[picture_thumb_url]: '../Style/Images/default_avatar.png'
border='0' height='50' width='50'/></a></td>";
echo "<td width='140' class='ordinary_text_12'>" .$row_user['user_first_name']. "</td>";
echo "<td width='140' class='ordinary_text_12'>" .$row_user['user_last_name']. "</td>";
echo "<td width='140' class='ordinary_text_12'>" .$row_user['username']. "</td>";
echo "<td width='30'><a class='text_12_link_green' href='user_view.php?user_id=".$row_user['user_id']."'>View</a></td>";
echo "\n\t</tr>";
echo "\n</table>";
}
?>
<?php
while ($row_event = mysql_fetch_assoc($event))
{
echo "\n<table width='500' border='0'>";
echo "\n\t<tr>";
echo "<td width='50' height='50' align='center' valign='middle'><a href='#table_index.php'>
<img src='Images/$row_event[event_thumb_url]' border='0' height='50' width='50'/></a></td>";
echo "<td width='140' class='ordinary_text_12'>" .$row_event['event_name']. "</td>";
echo "<td width='140' class='ordinary_text_12'>" .$row_event['event_venue']. "</td>";
echo "<td width='140' class='ordinary_text_12'>" .$row_event['event_date']. "</td>";
echo "<td width='30'><a class='text_12_link_green' href='#user_view.php?user_id=".$row_user['username']."'>View</a></td>";
echo "\n\t</tr>";
echo "\n</table>";
}
?>
<?php
while ($row_establishment = mysql_fetch_assoc($establishment))
{
echo "\n<table width='500' border='0'>";
echo "\n\t<tr>";
echo "<td width='50' height='50' align='center' valign='middle'><a href='#table_index.php'>
<img src='Establishment_Images/$row_establishment[establishment_thumb_url]' border='0' height='50' width='50'/></a></td>";
echo "<td width='140' class='ordinary_text_12'>" .$row_establishment['establishment_name']. "</td>";
echo "<td width='140' class='ordinary_text_12'>" .$row_establishment['location_name']. "</td>";
echo "<td width='140' class='ordinary_text_12'>" .$row_establishment['establishment_pricing']. "</td>";
echo "<td width='30'><a class='text_12_link_green' href='#user_view.php?user_id=".$row_user['username']."'>View</a></td>";
echo "\n\t</tr>";
echo "\n</table>";
}
?>
The problem is in the $row_user while loop where im trying to echo $row_user thumb. Right now, if a user has an avatar, it displays the image, however it returns no image at all if a user has no avatar. Where am I going wrong?
you can do this although it's not exactly readable.
echo "<td width='50' height='50' align='center' valign='middle'><a href='user_view.php?user_id=".$row_user['user_id']."'>
<img src=User_Images/" . ( $row_user['picture_thumb_url'] != '' ? $row_user['picture_thumb_url'] : '../Style/Images/default_avatar.png' ) . " border='0' height='50' width='50'/></a></td>";
You're best of doing the conditional beforehand then echo the variable:
Updated:
$thumbnail = $row_user['picture_thumb_url'] != '' ? $row_user['picture_thumb_url'] : '../Style/Images/default_avatar.png';
echo "<td width='50' height='50' align='center' valign='middle'><a href='user_view.php?user_id=".$row_user['user_id']."'>
<img src=User_Images/$thumbnail border='0' height='50' width='50'/></a></td>";
You cannot put an 'if' statement into your 'echo'.
Go this way:
if($row_user[picture_thumb_url] !='')
$thumb = $row_user[picture_thumb_url];
else
$thumb = '../Style/Images/default_avatar.png';
And then:
echo "<img src=\"$thumb\">";
Related
I want to make an (html) list of products that have the same unique number behind the full stop (.). For example, 1.0001 is white bread sold on Monday 2.0001 is white bread sold on Tuesday and so on.
Now I want to make a list that sums of all white bread sold throughout the week. This is what I have so far:
<?php
echo "<table border='1' style='border-collapse: collapse;border-color: silver;'>";
echo "<tr style='font-weight: bold;'>";
echo "<td width='100' align='center'>Produkt</td><td width='100' align='center'>Baklijst</td>";
include("dbopen.php");
$result = mysql_query(
"SELECT order_item_name, SUM( product_quantity )
FROM wntl_virtuemart_order_items
WHERE wntl_virtuemart_order_items.order_item_sku REGEXP '0001$'
AND order_status = 'U'");
while($row=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td align='center' width='200'>" . $row['order_item_name'] . "</td>";
echo "<td align='center' width='200'>" . $row['SUM(product_quantity)'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
output:
Notice: Undefined index: SUM(product_quantity) in *.php on line 17
Try this:
<?php
echo "<table border='1' style='border-collapse: collapse;border-color: silver;'>";
echo "<tr style='font-weight: bold;'>";
echo "<td width='100' align='center'>Produkt</td><td width='100' align='center'>Baklijst</td>";
include("dbopen.php");
$result = mysql_query(
"SELECT order_item_name, SUM( product_quantity ) AS Sum
FROM wntl_virtuemart_order_items
WHERE wntl_virtuemart_order_items.order_item_sku REGEXP '0001$'
AND order_status = 'U'");
while($row=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td align='center' width='200'>" . $row['order_item_name'] . "</td>";
echo "<td align='center' width='200'>" . $row['Sum'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
I am trying to display data from data base. I want to make it grouped. Here is the template
I made the code like this :
<?php
$queg=pg_query("SELECT agentgroup.leadername,agentgroup.reviewername, agentgroup.supervisorname, agent.onlinename from agentgroup left join agent on agentgroup.agentid=agent.agentid order by agentgroup.leadername");
echo "<td class=\"form1\" align=\"center\" > Number </td>";
echo "<td class=\"form1\" align=\"center\" > Agent Group </td>";
echo "<td class=\"form1\" align=\"center\" > Coach </td>";
echo "<td class=\"form1\" align=\"center\" > Supervisor </td>";
echo "<td class=\"form1\" align=\"center\" > Agent Online Name </td>";
echo "<td class=\"form1\" align=\"center\" ></td>";
$gcount=1;
while($grow=pg_fetch_array($queg)){
echo "<tr>";
echo "<td class=\"forma\" rowspan=\"8\" align=\"center\"> ".$gcount++."</td>";
echo "<td class=\"forma\" rowspan=\"8\" align=\"left\"style=\"padding-left:10%;\"> ".$grow['leadername']." </td>";
echo "<td class=\"forma\" rowspan=\"8\" align=\"left\"style=\"padding-left:10%;\"> ".$grow['reviewername']." </td>";
echo "<td class=\"forma\" rowspan=\"8\" align=\"left\"style=\"padding-left:10%;\"> ".$grow['supervisorname']." </td>";
echo "<td class=\"forma\" align=\"left\"style=\"padding-left:10%;\"> ".$grow['onlinename']." </td>";
echo "<td class=\"forma\" rowspan=\"4"align=\"center\"><a href=\"#\" >edit</a></td>
</tr>";}
?>
But I got chaos.this is the current output
Any help to display those data? Thank you :D
The database design was wrong I guess. In case its already happen, than u shouldnt display the data like that. try to pass the specified data to new page via url ( href ) and then display them one by one by specify the coach or agent group
<?php
$queg=pg_query("SELECT distinct leadername, reviewername, supervisorname from agentgroup order by leadername");
echo "<td class=\"form1\" align=\"center\" > Number </td>";
echo "<td class=\"form1\" align=\"center\" > Agent Group </td>";
echo "<td class=\"form1\" align=\"center\" > Coach </td>";
echo "<td class=\"form1\" align=\"center\" > Supervisor </td>";
echo "<td class=\"form1\" align=\"center\" ></td>";
echo "<td class=\"form1\" align=\"center\" ></td>";
$gcount=1;
while($grow=pg_fetch_array($queg))
{
echo "<tr>";
echo "<td class=\"forma\" align=\"center\"> ".$gcount++."</td>";
echo "<td class=\"forma\" align=\"left\"style=\"padding-left:10%;\"> ".$grow['leadername']." </td>";
echo "<td class=\"forma\" align=\"left\"style=\"padding-left:10%;\"> ".$grow['reviewername']." </td>";
echo "<td class=\"forma\" align=\"left\"style=\"padding-left:10%;\"> ".$grow['supervisorname']." </td>";
echo "<td class=\"form2\" align=\"center\"><a href=viewpergorup.php?viewnamegroup=".urlencode($grow['leadername'])."><img src=\"image\\view.png\" width=\"20px\" height=\"20px\" style=\"padding-left:22%;cursor:pointer;\"></td>";
}
make the page : view_agentgroup. There the details is displayed
This code is not passing URL to make topic clickable main problem is in third line after while loop. I got this error :
Parse error: syntax error, unexpected 'id' (T_STRING), expecting ',' or ';' in D:\xmapp\htdocs\forum\main_forum.php on line 37
Code :
while($rows=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td align='center' bgcolor=#FFFFFF>",$rows['id'],"</td>";
echo "<td bgcolor='#FFFFFF'>",'$rows['topic']. ',"</td>";
echo "<td align='center' bgcolor='#FFFFFF'>",$rows['view'],"</td>";
echo "<td align='center' bgcolor='#FFFFFF'>",$rows['reply'],"</td>";
echo "<td align='center' bgcolor='#FFFFFF'>",$rows['datetime'],"</td>";
}
Please try this. there is syntax error in your code.
echo "<tr>";
echo "<td align='center' bgcolor=#FFFFFF>",$rows['id'],"</td>";
echo "<td bgcolor='#FFFFFF'>",''.$rows[topic]. ' ',"</td>";
echo "<td align='center' bgcolor='#FFFFFF'>",$rows['view'],"</td>";
echo "<td align='center' bgcolor='#FFFFFF'>",$rows['reply'],"</td>";
echo "<td align='center' bgcolor='#FFFFFF'>",$rows['datetime'],"</td>";
This should correct your problem, Use
echo "<td bgcolor='#FFFFFF'><a href='".$view_topic.".php?id=".$rows['id']."'>".$rows['topic']."</a></td>";
instead of
echo "<td bgcolor='#FFFFFF'>",'$rows['topic']. ',"</td>";
One more thing, Why dont you use php tag only when needed. If you do like this it will be clean and easy.
<?php
while($rows=mysql_fetch_array($result))
{
?>
<tr>
<td> <?php $rows['topic']; ?> </td>
.......
.......
</tr>
<?php } ?>
Try this :
while($rows = mysql_fetch_array($result)){
echo "<tr>";
echo "<td align='center' bgcolor=#FFFFFF>".$rows['id']."</td>";
echo "<td bgcolor='#FFFFFF'><a href='".$view_topic.".php?id=".$rows['id']."'>".$rows['topic']."</a></td>";
echo "<td align='center' bgcolor='#FFFFFF'>".$rows['view']."</td>";
echo "<td align='center' bgcolor='#FFFFFF'>".$rows['reply']."</td>";
echo "<td align='center' bgcolor='#FFFFFF'>".$rows['datetime']."</td>";
}
T have one page on which results are get created dynamically. And I
want to display popup window on clicking image named view.jpg. The
image is hyperlink. So please tell me how should i do it. I am showing
my code as follows.
code :
echo "<table width='' height='' border='1' align='center'>
<tr><td>Title</td>
<td >Type</td>
<td >Date</td>
<td>Expiry Date</td>";
if($typeofuser=='admin' || $typeofuser=='Accountant' || $typeofuser=='secretary')
{
echo "<td>View</td>
<td>Edit</td>
<td>Delete</td>";
}
echo "</tr>";
$qry2 = mysqli_query($con,"SELECT nId,nTitle,nDescription,nDate,nExpiryDate FROM tblnoticemanager where Society_id = '$socId' and category='General'") or die(mysqli_error($con));
while($NoticeData = mysqli_fetch_array($qry2))
{
echo "<tr>";
echo "<td align='center' class='tdletter' style='text-transform:capitalize;'>" .$NoticeData['nTitle']. "</td>";
echo "<td align='center' class='tdletter' ><div class='overflowDiv'>" . $NoticeData['nDescription']."</div></td>";
echo "<td align='center' class='tdletter'>" . $NoticeData['nDate'] ."</td>";
echo "<td align='center' class='tdletter'>" . $NoticeData['nExpiryDate'] ."</td>";
if($typeofuser=='admin' || $typeofuser=='Accountant' || $typeofuser=='secretary')
{
echo "<td align='center' class='tdletter'><div><a href='?id=".urlencode(base64_encode($NoticeData['nId']))."'><img src='images/view.png' width='30' height='30' align='center' /></a></div></td>";
echo "<td align='center' class='tdletter'><div><a href='?id=".urlencode(base64_encode($NoticeData['nId']))."' ><img src='images/edit.jpg' width='30' height='30' align='center'/></a></div></td>";
echo "<td align='center' class='tdletter'><span id='".$NoticeData['nId']."' class='trash'><img src='images/delete1.jpg' width='30' height='30' align='center' /></span></td>";
}
echo "</tr>";
}
echo "</table>";
You can use attribute selector [attribute='value']
$("[src='images/view.png']").click(function(){
alert("clicked");
});
I am relatively new to php/mysql. I am trying to do carriage returns for this part:
echo "<td colspan='5'>" . nl2br($row['dish_description']) . "</td>";
"dish_description" contains some text which includes "\n"
e.g. "Served with salad and mint sauce. \n Contains beef." In the MySQL database
however I cannot display the carriage return.
<?php
require_once 'login.php';
$con = mysql_connect($db_hostname, $db_username, $db_password);
mysql_select_db($db_database) or die("Unable to select database". mysql_error());
$result = mysql_query("SELECT * FROM `dishes` ORDER BY `dishes`.`dish_id` ASC LIMIT 0 , 200");
echo '<table align="center">
';
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td style='width: 60px'></td>";
echo "<th style='width: 100px'>Dish No</th>";
echo "<td style='width: 70px'>" . $row['dish_id'] . "</td>";
echo "<th style='width: 100px'>Dish Name</th>";
echo "<td style='width: 120px'>" . $row['dish_name'] . "</td>";
echo "<th style='width: 120px'>Dish Price</th>";
echo "<td>£" . $row['dish_price'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td style='width: 75px'></td>";
echo "<th style='width: 100px'>Vegetarian</th>";
echo "<td style='width: 70px'>" . $row['dish_vegetarian'] ."</td>";
echo "<td style='width: 100px'></td>";
echo "<td style='width: 70px'></td>";
echo "<th style='width: 120px'>Contains Nuts</th>";
echo "<td style='width: 120px'>" . $row['dish_nuts'] ."</td>";
echo "</tr>";
echo "<tr>";
echo "<td style='width: 75px'></td>";
echo "<th style='width: 100px'>Information</th>";
***echo "<td colspan='5'>" . nl2br($row['dish_description']) . "</td>";***
echo "</tr>";
echo "<tr height='10px'>";
echo "<td style='width: 75px'></td>";
echo "<td style='width: 100px'></td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
In my opinion if you echo it as HTML you can just add <br> tags to your records in database.