PHP - Display Null Only
I'm trying to display the null values only, where am I going wrong?
SELECT IFNULL(trans, 0) AS 'Transactions', customer.cID AS 'Customer ID', customer.surname AS 'Surname' FROM customer LEFT JOIN account ON (account.cID = customer.cID) WHERE IFNULL(trans, 0); Similar TutorialsOk I'm setting the error. I debugged my code and it's catching the phrase in the set_error() function. But it's returning NULL when I try to display it from the display_error() function. These functions are in the form class. I create a new instance of it on the register.php and I'm trying to grab the values. Here is my Form class (only showing the part you need to see): Code: [Select] class Form { private $error; public function set_error($errmsg){ $this->error = $errmsg; return; } public function display_error() { $error = "<p style='color:red;'>".$this->error."</p>"; return $error; } } Then here is my register process: Code: [Select] if(isset($_POST['submit'])) { if(isset($_POST['name']) && isset($_POST['username']) && isset($_POST['password']) && isset($_POST['password2']) && isset($_POST['email']) && isset($_POST['email2']) && isset($_POST['dob']) && isset($_POST['gender']) && isset($_POST['security'])) { if ($user->register_user($_POST['name'], $_POST['username'], $_POST['password'], $_POST['password2'], $_POST['email'], $_POST['email2'], $_POST['dob'], $_POST['gender'], $_POST['security'])) { $message = "User has been registered successfully."; } else { $message = $form->display_error(); } } else { $message = "Please fill out all parts of the form!"; } } It display the $message just fine when I call isset($message), but it won't display it when I assign it the form->display_error() value because it returns NULL. Thank you! I am trying to update the database with isset to set the value of the variable to either null or the value entered by the user. Currently, if no value has been entered null is being set as a string causing the date field to populate with zeros. How do I code it so that it populates or sets the value as null and not as string null?
Here's my code: (yes I know sql injections it's still in development )
<?php Hello All, I tried searching here and google, but couldn't figure it out on my own... still Bellow is my code, I need some help figuring out how to tell PHP that "If picture is NULL, don't try to display it." Basically I have a dynamic news system set up. Some stories have pictures, some do not. I need PHP to not display the code for showing the picture if the picture value = NULL. Any help would be appreciated! <?php include ("../../includes/connections/newsconnection.php"); $id=$_GET['id']; //declare the SQL statement that will query the database $query = " SELECT * FROM news WHERE id='$id' "; //execute the SQL query and return records $result = mssql_query($query); //display the results //id, school, date, link, title, story, picture while($row = mssql_fetch_array($result)) { echo "<span class='bodyb'>"; echo $row["title"]; echo "</span>"; echo "<br /><i>"; echo date('l, F j, Y', strtotime($row['date'])); echo "</i>"; echo "<br /><br />"; //heres where I need to stop if picture is null echo "<img src='../../images/news/"; echo $row["picture"]; echo "' align='left' class='imgspacer-left'>"; echo fixQuotes($row["story"]); } //close the connection mssql_close($dbhandle); ?> How can I change Yes to No for the NULL field in the mysql db structure. E.g. (Table name: address and Column name : state) <?php $link = mysql_connect("localhost","db","pw"); mysql_select_db("db"); mysql_query("alter table address modify state null NO); $result = mysql_query($query); $sent = "Edit Successful."; echo ($sent); ?> My code; $sql = "SELECT SUM(IF(`submitdate` IS NULL , 1 , 0 )) as 'Survey Started But Not Completed' FROM `survey_$surveyid`"; $statement = $dbh->prepare($sql); $statement->execute(); $result = $statement->fetch(PDO::FETCH_OBJ); //pass that data to an objectIs returning; stdClass Object ( [Survey Started But Not Completed] => ) I need to set this to a vaule that I can actually print out on the screen... Like a "0" for example. At the moment it is just a NULL. How do I do this?? These don't work; $result = 0; $result = array(['Survey Started But Not Completed'] => "0"); hi all, i have a script in where the user enters there post code and it will provide a price for delivery, how would i echo "please contact us for price" if the db record for the price is (null) or empty?? <?php mysql_connect ("localhost", "root","password") or die (mysql_error()); mysql_select_db ("postcode"); $term = $_POST['term']; $sql = mysql_query("SELECT * FROM uk_postcodes, zones WHERE postcode LIKE '%$term%' AND zone_id = zone_large "); while ($row = mysql_fetch_array($sql)){ echo '<br/> Postcode: '.$row['postcode']; echo '<br/> Town: '.$row['town']; echo '<br/> County: '.$row['county']; echo '<br/> Small: £'.$row['price_s']; echo '<br/> Medium: £'.$row['price_m']; echo '<br/> Large: £'.$row['price_l']; echo '<br/><br/>'; } ?> I'm trying to force a NULL value into the database with a hidden value and I can't seem to get it to work. Any suggestions? <input type="hidden" name="inactive" value=""/> I also tried here too: $sql="UPDATE product SET inactive='NULL' WHERE id = '$item_id'"; I have a php page where user/db info is being passed: <?php include "include/dbc.php"; include "include/header.inc"; $exerciseid = $_POST["exerciseid"]; $duration = $_POST["duration"]; $distance = $_POST["distance"]; $metric = $_POST["metric"]; echo'<h1>Added Activities</h1>'; // name of array echo '<h1>Exercise</h1>'; if (is_array($exerciseid)) { foreach ($exerciseid as $key => $value) { echo $key .' : '. $value .'<br />'; } } // name of array echo '<h1>Duration</h1>'; if (is_array($duration)) { foreach ($duration as $key => $value) { echo $key .' : '. $value .'<br />'; } } // name of array echo '<h1>Distance</h1>'; if (is_array($distance)) { foreach ($distance as $key => $value) { echo $key .' : '. $value .'<br />'; } } // name of array echo '<h1>Metric</h1>'; if (is_array($metric)) { foreach ($metric as $key => $value) { echo $key .' : '. $value .'<br />'; } } ?> And here is the output from that code: Added Activities Exercise 0 : Canoeing, on camping trip 1 : Canoeing, rowing, over 6 mph, vigorous effort 2 : Canoeing, rowing, crewing, competition 3 : Canoeing, rowing, light effort 4 : Canoeing, rowing, moderate effort 5 : Diving, springboard or platform 6 : Kayaking 7 : Sailing, boat/board, windsurfing, general 8 : Sailing, in competition 9 : Skiing, water 10 : Ski-mobiling, water 11 : Skin diving, scuba diving, general 12 : Snorkeling 13 : Surfing, body or board 14 : Swimming laps, freestyle, fast, vigorous effort 15 : Swimming laps, freestyle, light/moderate effort 16 : Swimming, backstroke, general 17 : Swimming, breaststroke, general 18 : Swimming, butterfly, general 19 : Swimming, leisurely, general 20 : Swimming, sidestroke, general 21 : Swimming, sychronized 22 : Swimming, treading water, fast/vigorous 23 : Swimming, treading water, moderate effort 24 : Water polo 25 : Water volleyball 26 : Whitewater rafting, kayaking, or canoeing Duration Canoeing, on camping trip : 20 Canoeing, rowing, over 6 mph, vigorous effort : Canoeing, rowing, crewing, competition : Canoeing, rowing, light effort : Canoeing, rowing, moderate effort : Diving, springboard or platform : Kayaking : Sailing, boat/board, windsurfing, general : Sailing, in competition : Skiing, water : Ski-mobiling, water : Skin diving, scuba diving, general : Snorkeling : Surfing, body or board : Swimming laps, freestyle, fast, vigorous effort : Swimming laps, freestyle, light/moderate effort : Swimming, backstroke, general : Swimming, breaststroke, general : Swimming, butterfly, general : Swimming, leisurely, general : Swimming, sidestroke, general : Swimming, sychronized : Swimming, treading water, fast/vigorous : Swimming, treading water, moderate effort : Water polo : Water volleyball : Whitewater rafting, kayaking, or canoeing : Distance Canoeing, on camping trip : 20 Canoeing, rowing, over 6 mph, vigorous effort : Canoeing, rowing, crewing, competition : Canoeing, rowing, light effort : Canoeing, rowing, moderate effort : Diving, springboard or platform : Kayaking : Sailing, boat/board, windsurfing, general : Sailing, in competition : Skiing, water : Ski-mobiling, water : Skin diving, scuba diving, general : Snorkeling : Surfing, body or board : Swimming laps, freestyle, fast, vigorous effort : Swimming laps, freestyle, light/moderate effort : Swimming, backstroke, general : Swimming, breaststroke, general : Swimming, butterfly, general : Swimming, leisurely, general : Swimming, sidestroke, general : Swimming, sychronized : Swimming, treading water, fast/vigorous : Swimming, treading water, moderate effort : Water polo : Water volleyball : Whitewater rafting, kayaking, or canoeing : Metric 0 : mile 1 : mile 2 : mile 3 : mile 4 : mile 5 : mile 6 : mile 7 : mile 8 : mile 9 : mile 10 : mile 11 : mile 12 : mile 13 : mile 14 : mile 15 : mile 16 : mile 17 : mile 18 : mile 19 : mile 20 : mile 21 : mile 22 : mile 23 : mile 24 : mile 25 : mile 26 : mile As you can see, null values are being passed as well. I am hoping that someone can show me the correct way to use php unset to get rid of these null values. Thank you. 2 PART QUESTION (so I don't have to ask two questions 😀 )
1.)
2.) On my particular coding, I can use either the NULL/isset style, or, the ""/== style, with no errors or ill effects.... but something tells me the expert PHP coders prefer one over the other... Thank you!! Edited July 10 by ChenXiuI have an array which can be empty; in this case, I get error. I want to skip when the array is empty. When calling the array from file, I use the following code if (file_exists($array_file)) { "the doing code" } else { echo "File does not exist"; } How I should use this If Else condition when array comes from a string like $test_array = explode(', ', $examplestring, -1); Can someone help me to get this code working... Code: [Select] public function getBowlContents(){ if is_null($this->contents) { return "The bowl is empty!"; } else { return "The bowl contains " . $this->contents . " soup!"; } TomTees I have a for loop that I am looping through. When I use var_dump() I get 10 results (which is what I should be getting). However, when I loop through it using a for() loop I am getting an extra 11th value that is blank. What would be causing this? My code is below: Code: [Select] $legacy = new Legacy(); // Loop through each film in the shopping cart for ($i = 0; $i < $myShoppingCartInfo['row_count']; $i++) { // Determine if the film is of a legacy series if ($legacy->isLegacyCheckout($myShoppingCartInfo['data']['PRODUCTSKUID'][$i])) { // Declare array to hold all legacy film entity_id values $legacyEntityIds = array(); $legacyEntityIds = $legacy->getLegacyEntityIds($myShoppingCartInfo['data']['PRODUCTSKUID'][$i]); var_dump($legacyEntityIds); // Loop through all legacy video entity_id's for ($i = 0; $i < $legacyEntityIds['data']['ENTITY_ID']; $i++) { // Grant streaming access to each entity id echo $legacyEntityIds['data']['ENTITY_ID'][$i] . '<br />'; // Insert the product into the order items table /*$query = "INSERT INTO tblOrderItems (OrderItemID, ProductSKUID, RentalDate, OrderID) VALUES (##newID##, '".$myShoppingCartInfo['data']['PRODUCTSKUID'][$i]."', ".($myShoppingCartInfo['data']['RENTALDATE'][$i] === NULL ? 'NULL' : "'".$myShoppingCartInfo['data']['RENTALDATE'][$i]."'").", ".$newOrderID.")"; $cartItemInserted = counter_id_insert($query,'OrderItemID'); $curr_user->addNewEntityLicense($legacyEntityIds['data']['ENTITY_ID'][$i]);*/ } } When I view the source code of the output page in a browser, this is what I see: array(5) { ["row_count"]=> int(10) ["col_count"]=> int(1) ["col_names"]=> array(1) { => string(9) "entity_id" } ["col_types"]=> array(1) { => string(3) "int" } ["data"]=> array(1) { ["ENTITY_ID"]=> array(10) { => string(7) "1681799" [1]=> string(7) "1681872" [2]=> string(7) "1681871" [3]=> string(7) "1681870" [4]=> string(7) "1681869" [5]=> string(7) "1681868" [6]=> string(7) "1681867" [7]=> string(7) "1681866" [8]=> string(7) "1681865" [9]=> string(7) "1681864" } } } 1681799<br />1681872<br />1681871<br />1681870<br />1681869<br />1681868<br />1681867<br />1681866<br />1681865<br />1681864<br /><br /> Hi... i have table EMP_NO LOGIN - DATETIME, NULL LOGOUT - DATETIME, NULL I have this query: Code: [Select] <?php include 'config.php'; $currentEmpID = $_SESSION['empID']; if(!isset($_POST['submit_'])){ $DATE1 = $_POST['firstinput']; $DATE2 = $_POST['secondinput']; $sql = "SELECT EMP_NO, LOGIN, LOGOUT FROM employee_attendance WHERE DATE(LOGIN) BETWEEN '$DATE1' AND '$DATE2'"; $attendance = $conn3->GetAll($sql); $smarty->assign('attendance', $attendance); } $smarty->display('header_att.tpl'); $smarty->display('empAttendance.tpl'); $smarty->display('footer.tpl'); ?> My problem is I have data EMP_NO 00000223 LOGIN NULL LGOUT NULL this data was not displayed because it has a null value.. i want it to displayed also and highlight it because it has a value null.. Thank you I have a column in my MySQL database "paid". I have values of p for PayPal, c for check, and f for free. Those who haven't paid the record is marked (NULL). Right now my code is: if ($line['paid'] == 'y') { echo '.</center></td>';} else { echo '</center></td>';} That works pretty well for when I was just using those who paid vs. those who didn't. However, I'm wanting my site to show who has paid vs. those who haven't, while my data table will easily show how they paid. I either need an array or I need to reverse the IF...ELSE to say IF it's NULL do nothing, ELSE mark paid. Dont understand why...my database is displayed correctly but cant seem to add edit delete etc, I just get the error above. Any clues please How can I check a variable to see if it is NULL and if so set to 0000-00-00? I've tried: if ($var IS NULL) THEN $var='0000-00-00'; to no avail. Good morning,
I am trying to convert a mssql query into json format so that I can then later pass this through google's visualisation api. The query and encoding seems to be working but the encode returns NULL.
I have checked the normal gotcha's of making sure its utf8 encoded and that I have used a version of PHP that has the encode (using php 5.3.19).
Can any one help me with getting the encode to work.
PHP CODE:
<?php How do I make my constructor work when I don't pass in an argument. That is, it should efault to null. Code: [Select] class Something{ private $type=null; public function __construct($t){ $this->type = $t; } public function setSomething($t){ $this->type = $t; } public function getSomething(){ if (is_null($this->type)) { return "None for you!"; } else { return "Something is " . $this->type . "."; } } } TomTees if ($rowcats->followersrange == "2000-5000") { $lowrange2000 = "2000"; $lowestrange = $lowrange2000; $numberpeople = $rowcats->numberpeople; } if ($rowcats->followersrange == "5000-10000") { $lowrange5000 = "5000"; if ($lowrange5000 < $lowestrange) { $lowestrange = $lowrange5000; $numberpeople = $rowcats->numberpeople;} } if ($rowcats->followersrange == "10000-15000") { $lowrange10000 = "10000"; if ($lowrange10000 < $lowestrange) { $lowestrange = "$lowrange10000"; $numberpeople = $rowcats->numberpeople;} if ($lowestrange == NULL) { echo "yes";} echo "$lowestrange"; } if ($rowcats->followersrange == "15000-20000") { $lowrange15000 = "15000"; if ($lowrange15000 < $lowestrange) { $lowestrange = $lowrange15000;$numberpeople = $rowcats->numberpeople;} } We are trying to find the lowest range from the entries added to a database, so at the end, we can say the range is FROM... TO... They might opt for 2-5k, or 5-10k etc. If they opt for 10-15k, then the lowest range is 10,000. We have a result of 10000 - 15000. So the $lowrange10000 = "10000". Therefore, this should be echoing the $lowestrange from 7th line up in this code, but it remains at NULL, based on: $lowestrange = NULL;, set at the top of the code. Why is that? Okay so I created a theme for my website that will also utilize a custom CMS script I developed and its not cooperating with me nicely. Here's my head of my header file for my template: Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>> <head> <title><?php bloginfo('name') ?>: <?php bloginfo('description') ?></title> <link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url' ); ?>" /> <meta http-equiv="content-type" content='<?php bloginfo("html_type"); ?> charset=<?php bloginfo('charset'); ?>' /> <?php if(is_singular()){ wp_enqueue_script('comment-reply');} ?> <?php wp_head(); ?> <?php require ('efedmanager/inc/dbconfig.php'); ?> </head> Now on my index page that calls the header file I DO NOT get a error saying that the file could not be located. So that's good news. Here's my dbconfig.php file. Code: [Select] <?php /** * @author Jeff Davidson * @copyright 2010 */ // This file contains the database access information and establishes a connection to MySQL and selects the database // Set the database access information as contstants DEFINE ('DB_USER', '?'); DEFINE ('DB_PASSWORD', '?'); DEFINE ('DB_HOST', '?'); DEFINE ('DB_NAME', '?'); // Make the database connection $dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); if (!$dbc) { die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); } ?> Now when I go to one of my custom pages like this one it brings up the message: Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /home/xtremer/public_html/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()'d code on line 38 Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home/xtremer/public_html/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()'d code on line 39 Code: [Select] <div id="champions" class="content"> <h1 class="pageheading">KOW Champions and Contenders</h1> <?php $championsQuery = " SELECT titles.titleName, titles.shortName, champions.champID, champions.con1ID, champions.con2ID, champions.con3ID, biochamp.shortName AS championshortName, biochamp.characterName AS champion, biocon1.shortName AS con1shortName, biocon1.characterName AS con1, biocon2.shortName AS con2shortName, biocon2.characterName AS con2, biocon3.shortName AS con3shortName, biocon3.characterName AS con3 FROM champions LEFT JOIN titles AS titles ON titles.ID = champions.titleID LEFT JOIN characters AS biochamp ON champions.champID = biochamp.ID LEFT JOIN characters AS biocon1 ON champions.con1ID = biocon1.ID LEFT JOIN characters AS biocon2 ON champions.con2ID = biocon2.ID LEFT JOIN characters AS biocon3 ON champions.con3ID = biocon3.ID WHERE titles.statusID = '1' ORDER BY titles.ID"; $championsResult = mysqli_query($dbc, $championsQuery); while ( $row = mysqli_fetch_array ( $championsResult, MYSQLI_ASSOC ) ) { $fieldarray=array('titleName','shortName','championID','championshortName','champion','con1ID','con1','con1shortName','con2ID','con2','con2shortName','con3ID','con3','con3shortName'); foreach ($fieldarray as $fieldlabel) { ${$fieldlabel} = $row[$fieldlabel]; } ?> <div id="title"><span class="large">< ?php echo $titleName ?></span> < ?php if (file_exists('images/championshots/'.$titleshortName.'/'.$championshortame.'.png')) { echo "<img class=champion src=images/championshots/".$shortName."/".$champion.".png alt= />\n"; } else { echo "<img class=champion src=images/championshots/".$shortName."/".$shortName.".png alt= />\n"; } if (strlen ($champion) < 1) { echo "<span class=medium>Vacant"; } else { echo "<span class=medium><a href=/bio?shortName=".$championshortName.">".$champion."</a></span>\n"; echo "<span class=medium>(Since TBD)</span>"; } ?> <span class="contender">Contenders</span> <ul> < ?php if ( strlen ($con1) < 1) { echo "<li><span class=medium>TBD</span>"; } else { echo "<li><a href=/bio?shortName=".$con1shortName.">".$con1."</a></li>\n"; } if (strlen ($con2) < 1) { echo "<li><span class=medium>TBD</span>"; } else { echo "<li><a href=/bio?shortName=".$con2shortName.">".$con2."</a></li>\n"; } if (strlen ($con3) < 1) { echo "<li><span class=medium>TBD</span>"; } else { echo "<li><a href=/bio?shortName=".$con3shortName.">".$con3."</a></li>\n"; } ?> </ul> </div> < ?php } ?> </div> |