PHP - Show Image If Recordset Empty
Hi again
probably a very simple code but not working. I am trying to show a default image "fabric.jpg" if the recordset is empty. If not empty it shows the recordset image at a size of 100X100. This is the code I am using and have probably left something out, any ideas? <img src="<?php if ($row_Recordset3['fabricpicture']==null); echo "<img src='graphics/fabric.jpg'>"; ?>" alt="" name="fabric" width="100" height="100" border="0" align="bottom" id="fabric" title="Selected Bottom Up Blind Fabric" /> I have tried switching the img scr both "" and ' ' but still no joy? Similar TutorialsHey guys i have a query echo (empty($row['deal'])? "empty": "not empty"); //result not empty but i need it to show the "not empty" if its "deal". by default it is a "1" when i select the row to be a deal it updates the table and inserts "Deal". What I am looking for is that if any field in a database is empty, the form comes back and puts in the word "empty" into the web page, but not the database. I got this right now, it shows the first part fine, but the second part it doesn't show the "Empty" comment... I don't understand why... as far as I can tell the code is fine... Code: [Select] <?php //Nonconformity, Disposition, Comments and Comments & Additional Details echo '<div id="box3">'; if (!empty($row['Nonconformity']) || !empty($row['Disposition']) || !empty($row['Comments']) || !empty($row['CommentsAdditional_Details'])) { echo '<div id="non"><span class="b">Nonconformity: </span><br />' . $row['Nonconformity'] . '</div>'; echo '<div id="dis"><span class="b">Disposition: </span><br />' . $row['Disposition'] . '</div>'; echo '<div id="comm"><span class="b">Comments: </span><br />' . $row['Comments'] . '</div>'; echo '<div id="comma"><span class="b">Comments and/or Additional Details: </span><br />' . $row['CommentsAdditional_Details'] . '</div>';} else if (empty($row['Nonconformity']) || empty($row['Disposition']) || empty($row['Comments']) || empty($row['CommentsAdditional_Details'])) { echo '<div id="non"><span class="b">Nonconformity: </span><br />Empty</div>'; echo '<div id="dis"><span class="b">Disposition: <br /></span>Empty</div>'; echo '<div id="comm"><span class="b">Comments: <br /></span>Empty</div>'; echo '<div id="comma"><span class="b">Comments and/or Additional Details: </span><br />Empty</div>';} echo '</div>'; ?> Hi all I have a pice of code that I want to only show the image if it's empty: Code: [Select] <?php if(!empty($node->field_img['und'][0]['filename'])); { ?> <li><img src="http://mysite.co.uk/sites/default/files/brand-images/<?php print $node->field_img['und'][0]['filename']; ?>" style="max-width:270px; text-align:center;" /></li> <?php } ?> However, it shows an image placeholder (Red cross) even when it's empty? Many thanks for your help Pete below is my mail code. I am not sure what I am doing wrong. It works in outlook every once in awhile. Code: [Select] $fileatt = "/srv/www/##/####/files/"; // Path to the file $fileatt_type = "application/octet-stream"; // File Type $fileatt_name = "license.bin.".$num; // Filename that will be used for the file as the attachment $email_from = "sales@email.com"; // Who the email is from $email_subject = "email. License"; // The Subject of the email $email_message = "Please download file."; // Message that the email has in it $email_to = $email; // Who the email is too $headers = "From: ".$email_from; $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; $email_message .= "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type:text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $email_message . "\n\n"; $file = fopen($fileatt,'rb'); $fileinfo = fread($file,filesize($fileatt)); fclose($file); $fileinfo = chunk_split(base64_encode($fileinfo)); $email_message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . //"Content-Disposition: attachment;\n" . //" filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $fileinfo . "\n\n" . "--{$mime_boundary}\n"; Can anyone see why I am having this issue? Hello: I'm trying to figure out how to NOT show emailed results if the checkbox is empty (not checked). I only want it included in the message of the email if the checkbox was checked. It is writing the data to the email properly, but it is including some of the code as well. This is my email code: Code: [Select] mail( "me@digital.com", "Sign-up Sheet Request", "Date Sent: $myDate\n Parent's Name: $ParentsName Best Phone: $BestPhone Email: $Email Student's Name: $StudentsName Student's School: $StudentsSchool\n\n if(trim($SATTest1) != \"\" ) { echo \"$SATTest1\"; } ", "From: $Email" ); The "$SATTest1" data is displaying properly in the emails, but so is some of the code. Like this: Code: [Select] if(trim(Reading and Math Classes for March 10) != "" ) { echo "Reading and Math Classes for March 10"; } Any idea how to correct this? Thanks! Hi All, Need help. I'm strugling to figure out how to write the code to display default image if no image is available. I'm able to display image if data is available. Not able figure how to echo if/else statment. Below is the code Code: [Select] <?php function perDetails($var1, $result, $var2){ $dft_img = 'lib/images/name.png'; echo '<div class="desc">'.$var1.'</div>'; $color="1"; echo '<table align="center" cellpadding="2" cellspacing="1">'; while($row = mysql_fetch_array($result)){ $id = $row['pid']; $name = $row['pname']; $img = $row['pphoto_localurl']; $poster = str_replace("./", "lib/", $img); if($color==1){ echo '<tr bgcolor="#FFC600"><td><img src="'.$poster.'" width="32" height="42" alt="'.$name.'"</td><td><a href="persons.php?det='.$var2.'&perid='.$id.'"> '.$name.'" </a></td></tr>'; $color="2"; } else { echo '<tr bgcolor="#C6FF00"><td><img src="'.$poster.'" width="32" height="42" alt="'.$name.'"</td><td><a href="persons.php?det='.$var2.'&perid='.$id.'"> '.$name.'" </a></td></tr>'; $color="1"; } } echo '</table>'; } ?> hi all i have a problem here, Iv got a form that uploads images to a folder and updates the db with the name of that image, that work ok but if one of the upload field are left blank then the script updates the db with empty values how can i get it to only update the db with only submitted form field data???? here is the form Code: [Select] <?php if (isset($_GET['id'])) { $id = $_GET['id']; } ?> <form action="ud_image.php?id=<? echo "$id"?>" method="post" enctype="multipart/form-data" name="form1" id="form1"> <table class="udp"> <tr> <th>Thumbnail:</th> <td><input type="hidden" name="MAX_FILE_SIZE" value="1029120" /> <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <th>Image 1:</th> <td><input type="hidden" name="MAX_FILE_SIZE" value="1029120" /> <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <th>Image 2:</th> <td><input type="hidden" name="MAX_FILE_SIZE" value="1029120" /> <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <th>Image 3:</th> <td><input type="hidden" name="MAX_FILE_SIZE" value="1029120" /> <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <th>Image 4:</th> <td><input type="hidden" name="MAX_FILE_SIZE" value="1029120" /> <input name="ufile[]" type="file" id="ufile[]" size="50" /><input type="submit" name="Submit" value="Upload" /></td> </tr> </table> </form> and here is the processing page <?php include("protect/password_protect.php"); error_reporting(E_ALL); include ("../includes/db_config.php"); $con = mysql_connect($db_hostname,$db_username,$db_password); @mysql_select_db($db_database) or die( "Unable to select database"); $path1= "../thumbnails/".$_FILES['ufile']['name'][0]; $path2= "../images/".$_FILES['ufile']['name'][1]; $path3= "../images/".$_FILES['ufile']['name'][2]; $path4= "../images/".$_FILES['ufile']['name'][3]; $path5= "../images/".$_FILES['ufile']['name'][4]; //copy file to where you want to store file copy($_FILES['ufile']['tmp_name'][0], $path1); copy($_FILES['ufile']['tmp_name'][1], $path2); copy($_FILES['ufile']['tmp_name'][2], $path3); copy($_FILES['ufile']['tmp_name'][3], $path4); copy($_FILES['ufile']['tmp_name'][4], $path5); ?> <html> <head> <title>Update Project Images</title> <link rel="stylesheet" type="text/css" href="../../project/backend/style.css" /> </head> <body> <table class="udip"> <tr> <th><? echo "<img src=\"$path1\" width=\"150\" height=\"150\">";?></th> <th><? echo "<img src=\"$path2\" width=\"150\" height=\"150\">";?></th> <th><? echo "<img src=\"$path3\" width=\"150\" height=\"150\">";?></th> <th><? echo "<img src=\"$path4\" width=\"150\" height=\"150\">";?></th> <th><? echo "<img src=\"$path5\" width=\"150\" height=\"150\">";?></th> </tr> <tr> <td><? echo "File Name :".$_FILES['ufile']['name'][0]."<BR/>";?></td> <td><? echo "File Name :".$_FILES['ufile']['name'][1]."<BR/>";?></td> <td><? echo "File Name :".$_FILES['ufile']['name'][2]."<BR/>";?></td> <td><? echo "File Name :".$_FILES['ufile']['name'][3]."<BR/>";?></td> <td><? echo "File Name :".$_FILES['ufile']['name'][4]."<BR/>";?></td> </tr> <tr> <td><?echo "File Size :".$_FILES['ufile']['size'][0]."<BR/>";?></td> <td><?echo "File Size :".$_FILES['ufile']['size'][1]."<BR/>";?></td> <td><?echo "File Size :".$_FILES['ufile']['size'][2]."<BR/>";?></td> <td><?echo "File Size :".$_FILES['ufile']['size'][3]."<BR/>";?></td> <td><?echo "File Size :".$_FILES['ufile']['size'][4]."<BR/>";?></td> </tr> <tr> <td><? echo "File Type :".$_FILES['ufile']['type'][0]."<BR/>";?></td> <td><? echo "File Type :".$_FILES['ufile']['type'][1]."<BR/>";?></td> <td><? echo "File Type :".$_FILES['ufile']['type'][2]."<BR/>";?></td> <td><? echo "File Type :".$_FILES['ufile']['type'][3]."<BR/>";?></td> <td><? echo "File Type :".$_FILES['ufile']['type'][4]."<BR/>";?></td> </tr> </table> </body> </html> <? $filesize1=$_FILES['ufile']['size'][0]; $filesize2=$_FILES['ufile']['size'][1]; $filesize3=$_FILES['ufile']['size'][2]; $filesize4=$_FILES['ufile']['size'][3]; $filesize5=$_FILES['ufile']['size'][4]; if($filesize1 && $filesize2 && $filesize3 && $filesize4 && $filesize5 != 0) { echo "We have recieved your files<p>"; } else { echo "Error in you images check and try again Database has been updated to blank images so no images will be shown on details page."; } $query = "UPDATE $db_table SET thumbnail = '".$_FILES['ufile']['name'][0]."', image1 = '".$_FILES['ufile']['name'][1]."', image2 = '".$_FILES['ufile']['name'][2]."', image3 = '".$_FILES['ufile']['name'][3]."', image4 = '".$_FILES['ufile']['name'][4]."' WHERE id = '".$_GET['id']."'"; if (!mysql_query($query,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con) ?> This is my pagination with the number bar: Code: [Select] <?php $page = $_GET['page']; $category = $_GET['cat']; $your_db = @ new mysqli("$hostname","$username", "$password"); if (mysqli_connect_errno()) { echo 'ERROR!<br />'.mysqli_connect_errno() .' - Not connected : '.mysqli_connect_error().'<br />'; die; } else { $db_connect = $your_db->select_db("database"); if (!$db_connect) { echo 'Error!'; die; } } echo '<p>'; $query = "select distinct fldCategory from tablename order by fldCategory"; $result = $your_db->query($query); $number_of_records = $result->num_rows; for ($i = 0; $i < $number_of_records; $i++) { $row = $result->fetch_assoc(); echo '<a href="page_name.php?cat='.stripslashes($row['fldCategory']).'">'; echo stripslashes($row['fldCategory']); echo '</a> / '; } echo '</p>'; if ($category) { $query = "select fldID, fldTitle, fldCategory, fldIconMedium, fldLink from tablename where fldCategory = '$category' order by fldCategory"; } else { $query = "select fldID, fldTitle, fldCategory, fldIconMedium, fldLink from tablename order by fldCategory"; } $result = $your_db->query($query); $number_of_records = $result->num_rows; $num_pages = $number_of_records / 7; if (($number_of_records % 7) > 0 ) { $num_pages++; } if (strlen($page) == 0) { $page = 0; } else { $page = $page * 7; } echo '<table border="1">'; $row_num = 1; $result->data_seek($page); for ($i = $page; $i < $number_of_records; $i++) { if ($row_num <= 7) { echo '<tr>'; for ($col_num = 0; $col_num < 5; $col_num++) { $row = $result->fetch_assoc(); echo '<td>'; show_image(stripslashes($row['fldIconMedium']),stripslashes($row['fldTitle'])); echo '<br />'; echo '<a href="'.stripslashes($row['fldLink']).'" target="_blank">'; echo stripslashes($row['fldTitle']); echo '</a>'; echo '</td>'; } $row_num++; echo '</tr>'; } else { break; } } echo '</table>'; for ($j = 0; $j < $num_pages; $j++) { $page_link = $j + 1; echo '<a href="page_name.php?page='.$j.'&cat='.$category.'">'.$page_link.'</a> '; } echo ' '.$number_of_records; function show_image($image_name, $alt) { if (file_exists("path_to_images/$image_name")) { $dim_img = getimagesize('path_to_images/'.$image_name); echo '<img src="path_to_images/'.$image_name.'" alt = '.$alt.' border=0 align="bottom"'; echo 'width = '. $dim_img[0] .' height = ' .$dim_img[1] . ' />'; } else echo 'NO IMAGE'; } ?> To see it in action, here is the link to the 'skill games' section of the pagination script: http://netroxy.com/games2.php?cat=skills Ok here is the issue 1. As you can see, all the results displayed in the pagination script is correct, but what confuses me is the extra blank images that continue on in the table of the pagination table. I tried replacing the queries to see if the extra blank images would be removed like this: Code: [Select] $query = "select fldID, fldTitle, fldCategory, fldIconMedium, fldLink from tablename where fldCategory = '$category' and length(fldIconMedium) > 0 order by fldCategory"; } else { $query = "select fldID, fldTitle, fldCategory, fldIconMedium, fldLink where length(fldIconMedium) > 0 from tablename order by fldCategory"; So you see, I used 'length(fldIconMedium) > 0' making images less than 0 to see if the rest of the blank images would disappear from the cells in the table. This has not worked. Hence 'fldIconMedium' is the column for the images in the mysql database. Visit the link and you'll see the extra blank images through the results. This also applies when search for other game categories, blank images appear and I cant remove those extra blank images from the table. How to update table records one by one.... I have a table with five records .. I am getting values of month from another function..I would like to fill the values of month into the table.(like jan feb mar april may) respectively in the first row instead of Average. my code is below $insquery = "select * from reporttmp"; $insresult = mysql_query($insquery, $link) or die("Error in sql sytax."); $fel=mysql_num_fields($insresult); $nro=mysql_num_rows($insresult); $i=1; if ($nro > 0) { while ($i < $nro - 1) { $monname = getmonthname($fmonth); $monname = $monname. " ". $fyear; $upquery = ("UPDATE reporttmp SET vdate ='$monname' where mysql_num_row($insresult)=$i"); if(!mysql_query($upquery, $link)) die ("Mysql error ....<p>".mysql_error()); $fmonth = $fmonth + 1; $i = $i + 1; } } [attachment deleted by admin] I don't know if this is the correct Forum to post this under but I'm trying to fill the values of a recordset into an array. Here is what I have but it doens't work so far. function fetch($info) { return mysql_fetch_array($info); } $Proddb = new mysql; $Proddb->connect(); $result = $Proddb->query("SELECT * FROM Colors WHERE id = '1'"); $row = $Proddb->fetch($result) foreach ($row as $value) { echo $value. "<br>"; } $Proddb-> close(); The array is outputting everything twice does anyone know why? Hi I have a recordset from a database which outputs a value of '% THOBEKA MFEKA::12110235675?' I need to seach the database based on the number between the :: and ? only. So for example '12110235675'. I have tried this with a sql statement using LIKE but its not working. How can I trim the value from the database so I only get the number out. The amount of characters before the :: can vary. Please can someone give me some advice asap. Rob Man, I'm having a rough week with questions--if you're following at home. Basically matching a Coach's first and last name to another table, which if matched will yield information about that coach's team. Code: [Select] // or get user by username $current_user = wp_get_current_user(); $current_first = $current_user->user_firstname; $current_last = $current_user->user_lastname; $current_id = $current_user->ID; echo '<div class="contact_form">'; echo $current_first . ' ' . $current_last .' :: '; $query = "SELECT * FROM schools WHERE coachFirst='".$current_first."' AND coachLast='".$current_last."'"; $result = mysql_query ($query); if(!$result) { echo 'There is not a match for your name.'; } else { while($school= mysql_fetch_array($result)) { echo $school['school'] . ' ' . $school['id']; include(ABSPATH ."wp-content/plugins/my-team/form.php"); } echo '</div>'; echo '<div class="roster">'; include(ABSPATH ."wp-content/plugins/my-team/roster.php"); echo '</div>'; } Hi,
I'm very new to php and to mysql and I was hoping someone would be kind enough to give me a hand. I'm trying to write a query that returns only one record set.
I'll paste what I have below and the error. I'm sure that I am doing something wrong that is right in front of my face but for the life of me I can't figure it out.
The relevant part of the code is:
require_once ('../mysqli_connect.php'); $movie_id = $_GET['movie_id']; $q = "SELECT * FROM movies WHERE movie_id = $movie_id"; $r = mysqli_query($dbc, $q); echo '<table cols="2" width="1100px" align="center"> <tr> <td align="left" width="240px"><img src="img/boxcovers/small/movie_' . $r['movie_id'] .'_small.jpg"></td> <td></td> </tr> The error I'm getting is: PHP Fatal error: Cannot use object of type mysqli_result as array Help! Two part question: 1) I have a MySql table called "lang_key", which will store all of the common text for a site, which will allow easy site modifications from the "non tech" admin. Now, I am creating a recordest that will pull the information from the table, and create a basic list of variables in php. For example: I connect to the database, and do a wildcard select. I can figure out how to set a basic php variable like the example below: Code: [Select] $query1 = "SELECT * FROM lang_key"; $result = mysql_query($query1); while($row = mysql_fetch_array($result)) { $template = $row['common_text']; } There are three fields in my lang_key table (unique_id, string_id, and common_text') What I want to do is take it a step further from the example and I want $template to be the value of "common_text" Where string_id = "curr_template" I hope this makes sense? I really just want to create my recordset and then populate the website with the recordset info. Part II Do you recommend that I use a lang_key database, or would it be simpler and more efficient to just create a lang page with static variables, and use the php file write option to update the page? Thanks!!! I have the code below: ---------------------------------------------------------------------- ------------------------------------ <div id="content"> <table width="998" border="0" cellspacing="4" id="stuff"> <?php do { ?> <tr> <td><?php echo $row_Recordset1['name']; ?></td> </tr> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> </table> <div id="spryTable" spry:region="ds1"> <table align="center"> <tr> <th spry:sort="name"> </th> </tr> <tr spry:repeat="ds1" spry:setrow="ds1" spry:hover="hover" spry:select="selected"> <td height="40" align="center">{name}</td> // green line <td height="40" align="center">{name}</td> //orange line </tr> </table> </div> ---------------------------------------------------------------------- -------------------------------- At the moment the green line of code will display the entire record of names, and the orange line displays the entire record again in another column of the table. The problem is, I want half the names to be printed in one column and the other half of names to be displayed in the other column. Can someone show me how to set the php code to do this? I've been trying various things for a while now without success. Thank you. Record set has 2 text fields in the form which is set in a full repeat recordset browse. So, we get a long list of every record in the database. However, I want to be able to click on a single record and make another page appear. I can do this if the display is set as a table without using a text field form -- just the record variable and using a hyperlink. But, I want to use the text field. Wrapping the form only gets me the value of the last record displayed. Help would be appreciated. I have a table called parties with 3 fields - partyid, partyname, linkid. For any linkid there will be a number of parties somewhere between 2 and 10. I can get a vertical list but have a couple of issues which I can't fix: I want to have a page that displays the list of partynames (alphabetically) horizontally rather than vertically within a piece of text. For example, "The parties linked to you are Party1, Party2, Party3" Also, ideally, I would like the word 'and' before the last Party name so, using the above example, I would get "The parties linked to you are Party1, Party2 and Party3" I have no idea how to do this or if it can be done. Any ideas would be VERY gratefully received. Thanks Hi, I have some images that I want to resize to a square dimention (40px 40px). However, not all image are square, so when they are resized, they lose their ration and look squashed. Is there a way I can display just a part of the original image, say 40px x 40px on the top middle of each image? I hope that makes sense Hi all, new to PHP and had a syntax question. I have the following code: print "<p>{$row['comment_createdate']}; This prints out a date from my sqlquery as a database datetime. I need to format it to display "Monday June 15, 2010 5:15 pm". I'm not sure how/where to attach a date() function to the record. (If it matters, the line above is inside of a loop going through several records). This really applies to attaching functions to columns within a recordset in general. Many thanks ahead of time. |