PHP - Correct Syntax For Echoing Variables With Values!
What would be the correct way to use returned sql results as variables. I have tried the way in my script, but Im unsure of how I can echo just one of the $nt variables further on in my script.
$code = $_GET['postcode']; $shortcode = substr($code,0,2); $query =mysql_query ("SELECT email FROM treesurgeons WHERE postcode like '%" . $shortcode . "%' ORDER BY companyName LIMIT 3"); echo mysql_error(); echo "<p>The email addresses you have requested are;</p>"; while($nt=mysql_fetch_row($query)){echo "$nt[0],$nt[1],$nt[2]<br>";} echo "<p>please use $nt[2] if you ever want to contact me</p>"; //this line doesnt work for me ?></body></html> is there is a way to assign variables such as; $nt[0] = $firstemail $nt[1] = $secondemail $nt[2] = $thirdemail this way I could use each of my sql values, just as I would any other variable? Similar TutorialsIt's pretty simple to see what I am trying to do here. For some reason all results in the table are the same exact cityName replacing all existing records. The echoed results are correct. I've include a small dump of my table as well. $query = "SELECT cityName FROM sys_city_dev_2"; $resource = mysqli_query($cxn, $query) or die("MySQL error: " . mysqli_error($cxn) . "<hr>\nQuery: $query"); while($result = mysqli_fetch_assoc($resource)) { $nox = $result['cityName']; $toUpper = ucfirst($nox); echo "$toUpper" . "<br />"; $setString = "UPDATE sys_city_dev_2 SET cityName = '" . $toUpper ."' WHERE cityName != ''"; mysqli_query($cxn,$setString); } 100 Records of table dump (pre running my script above): -- -- Table structure for table `sys_city_dev_2_backup` -- CREATE TABLE IF NOT EXISTS `sys_city_dev_2_backup` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `Mid` int(11) NOT NULL DEFAULT '0', `cityName` varchar(30) NOT NULL DEFAULT '', `forder` int(4) NOT NULL DEFAULT '0', `disdplay` int(4) NOT NULL DEFAULT '0', `cid` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=113970 ; -- -- Dumping data for table `sys_city_dev_2_backup` -- INSERT INTO `sys_city_dev_2_backup` (`ID`, `Mid`, `cityName`, `forder`, `disdplay`, `cid`) VALUES (84010, 1, 'dothan', 0, 0, 0), (84011, 1, 'alabaster', 0, 0, 0), (84012, 1, 'birmingham', 0, 0, 0), (84013, 2, 'flagstaff', 0, 0, 0), (84014, 1, 'auburn', 0, 0, 0), (84015, 1, 'florence', 0, 0, 0), (84016, 1, 'gadsden', 0, 0, 0), (84017, 1, 'huntsville', 0, 0, 0), (84018, 1, 'mobile', 0, 0, 0), (84019, 1, 'montgomery', 0, 0, 0), (84020, 1, 'tuscaloosa', 0, 0, 0), (84021, 2, 'mohave valley', 0, 0, 0), (84022, 2, 'phoenix', 0, 0, 0), (84023, 2, 'prescott', 0, 0, 0), (84024, 2, 'sierra vista', 0, 0, 0), (84025, 2, 'tucson', 0, 0, 0), (84026, 2, 'yuma', 0, 0, 0), (84027, 3, 'bakersfield', 0, 0, 0), (84028, 3, 'chico', 0, 0, 0), (84029, 3, 'fresno / madera', 0, 0, 0), (84030, 3, 'gold country', 0, 0, 0), (84031, 3, 'humboldt county', 0, 0, 0), (84032, 3, 'imperial', 0, 0, 0), (84033, 3, 'inland empire', 0, 0, 0), (84034, 3, 'los angeles', 0, 0, 0), (84035, 3, 'alhambra', 0, 0, 0), (84036, 3, 'merced', 0, 0, 0), (84037, 49, 'fayetteville', 0, 0, 0), (84038, 49, 'fort smith', 0, 0, 0), (84039, 49, 'jonesboro', 0, 0, 0), (84040, 49, 'little rock', 0, 0, 0), (84041, 49, 'arkadelphia', 0, 0, 0), (84042, 49, 'texarkana', 0, 0, 0), (84043, 3, 'modesto', 0, 0, 0), (84044, 3, 'alta sierra', 0, 0, 0), (84045, 3, 'alpine', 0, 0, 0), (84046, 3, 'pedley', 0, 0, 0), (84047, 3, 'redding', 0, 0, 0), (84048, 3, 'alondra park', 0, 0, 0), (84049, 3, 'sacramento', 0, 0, 0), (84050, 4, 'canon city', 0, 0, 0), (84051, 3, 'san luis obispo', 0, 0, 0), (84052, 3, 'santa barbara', 0, 0, 0), (84053, 3, 'stockton', 0, 0, 0), (84054, 3, 'aliso viejo', 0, 0, 0), (84055, 3, 'visalia', 0, 0, 0), (84056, 3, 'yuba city', 0, 0, 0), (84057, 4, 'boulder', 0, 0, 0), (84058, 4, 'colorado springs', 0, 0, 0), (84059, 4, 'denver', 0, 0, 0), (84060, 4, 'applewood', 0, 0, 0), (84061, 4, 'pueblo', 0, 0, 0), (84062, 4, 'air force academy', 0, 0, 0), (84063, 5, 'avon', 0, 0, 0), (84064, 5, 'hartford', 0, 0, 0), (84065, 5, 'new haven', 0, 0, 0), (84066, 5, 'ansonia', 0, 0, 0), (84067, 5, 'fairfield', 0, 0, 0), (84068, 7, 'daytona beach', 0, 0, 0), (84069, 7, 'sebastian', 0, 0, 0), (84070, 5, 'wallingford center', 0, 0, 0), (84071, 8, 'belvedere park', 0, 0, 0), (84072, 7, 'sarasota springs', 0, 0, 0), (84073, 7, 'sandalfoot cove', 0, 0, 0), (84074, 7, 'san carlos park', 0, 0, 0), (84075, 7, 'st. augustine', 0, 0, 0), (84076, 7, 'tallahassee', 0, 0, 0), (84077, 7, 'safety harbor', 0, 0, 0), (84078, 7, 'ruskin', 0, 0, 0), (84079, 8, 'athens-clarke county', 0, 0, 0), (84080, 8, 'atlanta', 0, 0, 0), (84081, 8, 'augusta-richmond county', 0, 0, 0), (84082, 8, 'brunswick', 0, 0, 0), (84083, 8, 'columbus', 0, 0, 0), (84084, 8, 'americus', 0, 0, 0), (84085, 8, 'acworth', 0, 0, 0), (84086, 8, 'valdosta', 0, 0, 0), (84087, 10, 'boise', 0, 0, 0), (84088, 10, 'ammon', 0, 0, 0), (84089, 10, 'moscow', 0, 0, 0), (84090, 10, 'blackfoot', 0, 0, 0), (84091, 10, 'twin falls', 0, 0, 0), (84092, 10, 'meridian', 0, 0, 0), (84093, 10, 'jerome', 0, 0, 0), (84094, 10, 'idaho falls', 0, 0, 0), (84095, 11, 'addison', 0, 0, 0), (84096, 10, 'garden city', 0, 0, 0), (84097, 10, 'eagle', 0, 0, 0), (84098, 10, 'chubbuck', 0, 0, 0), (84099, 10, 'caldwell', 0, 0, 0), (84100, 12, 'bloomington', 0, 0, 0), (84101, 12, 'evansville', 0, 0, 0), (84102, 12, 'fort wayne', 0, 0, 0), (84103, 12, 'indianapolis', 0, 0, 0), (84104, 12, 'muncie / anderson', 0, 0, 0), (84105, 12, 'lafayette / west lafayette', 0, 0, 0), (84106, 12, 'south bend / michiana', 0, 0, 0), (84107, 12, 'terre haute', 0, 0, 0), (84108, 12, 'northwest indiana', 0, 0, 0), (84109, 13, 'ames', 0, 0, 0); Hey all, I'm using $_POST to post search variables from a search form i have made for my site. Below is the code for the search form: Code: [Select] <form method="post" action="results.php"> <p class="label">Airline </p><p class="right"> <select style="width: 200px;" name="airline" id="airline"> <option selected="selected" value=""> All Airlines</option> <?php $query=mysql_query("SELECT * FROM photos GROUP BY airline, aircraft ORDER BY airline"); while($row = mysql_fetch_assoc($query)){ echo '<option value="'.$row['airline'].'">'.$row['airline'].'</option>'; } ?> </select></p><br /><br /> <p class="label">Aircraft </p><p class="right"> <select style="width: 200px;" name="aircraft" id="aircraft"> <option selected="selected" value=""> All Aircraft</option> <?php $query=mysql_query("SELECT * FROM photos GROUP BY aircraft ORDER BY aircraft"); while($row = mysql_fetch_assoc($query)){ echo '<option value="'.$row['aircraft'].'">'.$row['aircraft'].'</option>'; } ?> </select></p><br /><br /> <p class="label">Registration </p><p class="right"><input type="text" style="width: 198px;" class="text" name="registration" id="registration" value="" /></p><br /><br /> <p class="label">Construction Number </p><p class="right"><input type="text" style="width: 198px;" class="text" name="cn" id="cn" value="" /></p><br /><br /> <p class="label">Location </p><p class="right"> <select class="select" style="width: 200px;" name="location" id="location"> <option selected="selected" value=""> All Locations</option> <?php $query=mysql_query("SELECT * FROM photos GROUP BY location ORDER BY location"); while($row = mysql_fetch_assoc($query)){ echo '<option value="'.$row['location'].'">'.$row['location'].'</option>'; } ?> </select></p><br /><br /><br /> <div class="options2"></div><br /><br /> <p class="label">Genre </p><p class="right"><select class="select" style="width: 200px;" name="class" id="class"> <option selected="selected" value=""> All Genres</option> <option> Airliner</option> <option> Cargo</option> <option> Executive/Private</option> <option> General Aviation</option> </select></p><br /><br /> <p class="label">Aspect/Subject </p><p class="right"><select class="select" style="width: 200px;" name="aspect" id="aspect"> <option selected="selected" value=""> All Aspects</option> <option> Cabin View</option> <option> Close Up</option> <option> Flight Deck</option> <option> Front View</option> <option> Rear View</option> <option> Side Profile</option> </select></p><br /><br /> <p class="label">Scheme </p><p class="right"> <select class="select" style="width: 200px;" name="scheme" id="scheme"> <option selected="selected" value=""> All Schemes</option> <option> Basic</option> <option> Extra Stickers</option> <option> Hybrid</option> <option> Special</option> <option> Standard</option> </select></p><br /><br /> <p class="label">Situation/Phase</p><p class="right"> <select class="select" style="width: 200px;" name="situation" id="situation"> <option selected="selected" value=""> All Situations</option> <option> Approach</option> <option> Departure</option> <option> Ground</option> </select></p><br /><br /> <p class="label">Time</p><p class="right"> <select class="select" style="width: 200px;" name="tod" id="tod"> <option selected="selected" value=""> All Times of Day</option> <option> Dawn and Dusk</option> <option> Day</option> <option> Night</option> </select></p><br /><br /><br /> <p class="label">Order By</p><p class="right"> <select class="select" style="width: 110px;" name="order" id="order"> <option selected="selected" value=""> Photo #</option> <option> Aircraft</option> <option> Airline</option> <option> Date of Photo</option> <option> Location</option> <option> Registration</option> </select> </p> <p class="right"> <br /><br /> <input type="submit" name="submit" id="submit" value=" Search " /> <input type="reset" name="reset" id="reset" value=" Reset " /> </form> On the results page i have this script: Code: [Select] if(!empty($_POST)) { $criteria= implode('</strong> > <strong>', array_map('htmlentities', $_POST)); } <p class="resulttext">Your search <?php if(!empty($_GET)) { echo 'for ';} ?> <strong><?php echo $criteria;?></strong> returned <strong><?php echo $num;?></strong> photo results, these are displayed below.</p> to echo the search variable. For example if someone used the form to search for 'British Airways' and 'London Heathrow', the results page would read: results.php?airline=British+Airways&location=London+Heathrow Your search for British Airways > London Heathrow has returned X photo results.... Although this is working; because there is often alot of form options not used, the url turn's out to be: results.php?airline=British+Airways&location=London+Heathrow&aircraft=®istration=&blah=&blah=&submit=search .....etc Which then reads as: Your search for British Airways > London Heathrow > > > > > SEARCH has returned X photo results.... as seen below in this pictu Is there anyway to stop this from happening and just echo the search field which !="" Thanks In Advanced! Hello. I have an array like this: Code: [Select] Array ( [1] => MOR [2] => CON [3] => CP1 [4] => CP2 [5] => EMAIL [6] => NIF [7] => BI [8] => DIS ) And then I defined, for example this one variable: define("DIS","District"); When I try to... echo $array[8]; All I get is "DIS". I'm obviously trying to echo a string and it won't work that way... but I still gave it a try. How can I do this then? I need "District" to be outputted instead of the actual variable name. I know that if I were to "echo DIS;" this would work but that defeats the purpose as I have various defined variables per row... Thanks. I am testing my app to server transport to verify everything is working, I need to write a loop that takes each value sent via GET and/or POST and then echo each key:value back, how do I step through the $_GET or $_POST and extract each to echo? Something like this, but what? <?php /*I know this is not valid, is psedocoded*/ foreach($key in $_GET as $value){ echo $key." = ".$value; } ?>
This is what i am trying to achieve for my URL categories=$pagename &id=$myid this is what i am currently doing having some syntax errors please would appreciate if some one can resolve this the code is below echo "<a href=\"./categories.php?name=".$pagename.&id=$myid."\">\".$myid.\".\"</a>\"\n"; $sql = "select * from {$tab} WHERE {$tab}_id ='".$id."'"; This was the error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE '_id' ='11/'' at line 1 I just had a curiosity that was bugging me and I'm unsure of how to google for the answer, so I thought I'd put it up to the test here. I learned that when writing if statements in php the syntax is as follows: if(condition){ //Execute Code... }else{ //Execute Other Code... } However, I also see it written like so: if(condition) { //Execute Code... } else { //Execute Other Code... } I thought that the later style was used for Javascript and the earlier for php. While they both work, I was wondering, which is more correct? Thanks Everybody! E I have just discovered ternary conditionals and really like the time and space saving, they seem pretty simple and look neater than a bunch of if else statements crammed together. The thing I would like to know is what is the best or correct method of usng the following; $page = isset($_GET['page']) ? $_GET['page'] : '1'; or do I need the extra parentheses like below; $page = (isset($_GET['page'])) ? $_GET['page'] : '1'; I understand that if I used a second conditon I would need the extra parentheses e.g $page = (isset($_GET['page']) && is_numeric($_GET[page'])) ? $_GET['page'] : '1'; Thanks! <?php error_reporting(E_ALL); session_start(); include ("dbcon.php"); echo "include working"; $username1= ($_POST['username']); echo ($_POST['username']); if ($_POST) { if (!empty($_POST['username']) && !empty($_POST['pass'])) { $sql = "SELECT * FROM `user` WHERE `username`='($_POST['username'])' LIMIT 1"; $result = mysqli_query($sql); if (mysqli_num_rows($result) > 0) { //user is valid, check pass $query = mysqli_fetch_assoc($result); $password = ($_POST['pass']); if ($password !== $query['pass']) { //invaid pass, input error code echo "Wrong Password"; exit; } else { //valid user and pass, login $_SESSION['login'] = TRUE; $_SESSION['username'] = $_POST['username']; //echo "logged in"; header('location: home.php'); exit(); } } else { //user is not in database, input error code echo " User Not Found"; } } else { //form submitted but no username/password, input error code echo "Fields are Blank"; } } else { //page loaded, but no form submitted, input error code echo "Submition Error"; } ?>I can't figure out the problem........ Any help is appreciated! <form action="blabla"> <input type="hidden" name="user" value="<?php echo $player;?>"> </form or <input type="hidden" name="user" value=<?php echo $player;?>> or are they both wrong ^_^ $tab is a variable for my table's name <?php while($row=mysqli_fetch_assoc($result)){ ?> <?php echo $row['{$tab}_name']?> Code: [Select] $query = "SELECT content FROM license WHERE serial = '".$serial."'"; Hi, I'm inserting hours and minutes per user into a database where they have their own fields. (userid, hours, mins) I've a small issue when displaying the data. When I run my query I sum the total hours and minutes per user which results in data such as the following userid1 - 2 hours 15 mins userid2 - 1 hour 100 mins The query orders by hours and then mins desc When I'm displaying the data (as I'm looping through the results array) I perform a calculation to convert the mins to hours so it now reads userid1 - 2 hours 15 mins userid2 - 2 hours 40 mins so the webpage displays userid1 first when i want userid2 to be the first record displayed (Hours desc) Can anyone recommend a solution to this ? Will I need to create another table and update it as hours and minutes are being entered and display results from that table instead ? Can I order the data after I carry out the mins to hours calculation ? many thanks in advance for any suggestions.... tmfl hi guys I have two functions and they work well, but now i have a problem in the last if the email is sent like www.yoursite.com/reset_password.php?userid=0&code= and not http://your.url/set_new_password.php?userid=564979&code=54c4a2767c2f485185ab72cdcf03ab59 so, the problem is that i can get the value of hash and the userid. If i do an echo "$hash" in the function code(); it shows the value like 564979&code=54c4a2767c2f485185ab72cdcf03ab59 my question is, how i can do the same in the last if? above two functions. Same occur in the last select select userid from password_reset where code=? none userid is showed, it is always zero. Code: [Select] <? function check($sql, $db, $email) { if(!empty($_POST['email'])) { $email = $_POST["email"]; if ($sql = $db->prepare("select email from users where email=?")) { $sql->bind_param('s', $email); $sql->execute(); $sql->bind_result($email); if ($sql->fetch()) { return true; } else { return false; } } } } function code($sql, $db, $hash, $pwdHasher, $userExists, $sendPass) { if (check($sql, $db, $email)) { $pwdHasher = new PasswordHash(8, FALSE); $hash = $pwdHasher->HashPassword($userExists["email"]); $sendPass=$hash; ($sql = $db->prepare('insert into password_reset (code) values (?)')); $sql->bind_param('s', $hash); $sql->execute(); $sql->fetch(); return true; } } if (code($sql, $db, $hash, $pwdHasher, $userExists, $sendPass)) { ($sql = $db->prepare("select userid from password_reset where code=?")); $sql->bind_param('s', $hash); $sql->execute(); $sql->bind_result($hash); $sql->fetch(); echo $hash; $pwrurl = "www.yoursite.com/reset_password.php?userid=" .$hash . "&code=" . $sendPass; $mailbody = "Dear user,<br><br>If this e-mail does not apply to you please ignore it. It appears that you have requested a password reset at our website www.yoursitehere.com<br> To reset your password, please click the link below. If you cannot click it, please paste it into your web browser's address bar.<br> <a href='$pwrurl'>$pwrurl</a> <br> <br> Thanks,\nThe Administration"; $mail->MsgHTML($mailbody); $mail->AddAddress($email,"Membro"); $mail->IsHTML(true); if(!$mail->Send()) { echo "Deu erro: " . $mail->ErrorInfo; } else { echo "Enviado com sucesso"; } $sql->close(); $db->close(); } ?> any help? thanks Hi, I have an affiliate system that shows results on what product is purchased. The problem is that the tracker is only listing the first product in the purchase list, so if someone purchases multiple products it only shows the first product in the transaction report. Here is the code: Code: [Select] $module = fetchDbConfig('PostAffiliatePro'); $orderInv = $order->getOrderInv($_GET["cart_order_id"]); print_r($orderInv); $affCode = "<!-- Begin PostAffiliatePro Affiliate Tracker --> <img border='0' src='".$module['URL']."/scripts/sale.php?TotalCost=".sprintf("%.2f", $orderSum['subtotal'])."&OrderID=".$cart_order_id."&ProductID=".$orderInv['0']['productCode']."' width='0' height='0' alt='' /> <!-- End PostAffiliatePro Affiliate Tracker -->"; ?> The code I need help with syntax is: Code: [Select] "&ProductID=".$orderInv['0']['productCode']."The products are split into arrays by number (0,1,2,3). So for example, I would want to show results for .$orderInv['0']['productCode']. , then .$orderInv['1']['productCode']. , and so on. I would like the results to be posted with a ; between them, but I don't know the proper syntax to have it report more than just the first array. This seems pretty simple, but I only know the basics of PHP and I've adapted this from found code. Any guidance would be greatly appreciated. Thanks! 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. Code: [Select] $query = mysql_query("SELECT name FROM business WHERE type ='Restaurant' ORDER BY name"); echo mysql_error(); while($ntx=mysql_fetch_row($query)) $nt[] = $ntx[0]; $i = -1; foreach($nt as $value) { $i++; echo $nt[$i]."<br/>";} Now im trying to swap the last line; Code: [Select] echo $nt[$i]."<br/>";} for somthing more like Code: [Select] echo "<a href="$nt[$i].html">$nt[$i]</a>";} My syntax seems to be shot to pieces, and i recieve errors. any ideas welcome? The error i receive is "Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' " Many thanks. Hi, I have a string with the value of { "success": true, "delivered": true, "contactDetailsRequired": false, "message": "Signed For by: D ANDERSON ", "signature": "https://webservices.thedx.co.uk/PodImage/ImageHandler.ashx?tn=906732192165", "date": "21-07-2020", "serviceLevelName": "Consigned", "time": "13:33:19", "trackedProductName": "DataExchange" } How do i go about placing the values into variables so for example: $success = "true"; $delivered = "true"; $message = "Signed for by: D ANDERSON"; etc.... My mind has gone blank and im having one of those days, any help would be greatly appreciated. Thanks Hi all, I am having some trouble with a script.. all works fine except for the calculation part. It isn't adding up, but the reason for this is because when I echoed all the variable it seems that they are blank, the problem is I can't figure out why? <?php # you don't display errors on in-use scripts, do you? ini_set('display_errors',0); error_reporting(E_ALL|E_STRICT); class webPoll { # makes some things more readable later const POLL = true; const VOTES = false; # number of pixels for 1% on display bars public $scale = 2; public $question = ''; public $answers = array(); private $header = '<form class="webPoll" method="post" action="%src%"> <input type="hidden" name="QID" value="%qid%" /> <h4>%question%</h4> <br /> <ul>'; private $center = ''; private $footer = "\n</ul>%button%\n</form>\n"; private $button = '<p class="buttons"><button type="submit">Vote!</button></p>'; private $md5 = ''; /** * --- * Takes an array containing the question and list of answers as an * argument. Creates the HTML for either the poll or the results depending * on if the user has already voted */ public function __construct($params) { $this->question = array_shift($params); $this->answers = $params; $this->md5 = md5($this->question); $this->header = str_replace('%src%', $_SERVER['SCRIPT_NAME'], $this->header); $this->header = str_replace('%qid%', $this->md5, $this->header); $this->header = str_replace('%question%', $this->question, $this->header); # seperate cookie for each individual poll isset($_COOKIE[$this->md5]) ? $this->poll(self::VOTES) : $this->poll(self::POLL); } private function poll($show_poll) { $replace = $show_poll ? $this->button : ''; $this->footer = str_replace('%button%', $replace, $this->footer); # static function doesn't have access to instance variable if(!$show_poll) { $results = webPoll::getData($this->md5); $votes = array_sum($results); } for( $x=0; $x<count($this->answers); $x++ ) { $this->center .= $show_poll ? $this->pollLine($x) : $this->voteLine($this->answers[$x],$results[$x],$votes); } echo $this->header, $this->center, $this->footer; } private function pollLine($x) { isset($this->answers[$x+1]) ? $class = 'bordered' : $class = ''; return " <li class='$class'> <label class='poll_active'> <input type='radio' name='AID' value='$x' /> {$this->answers[$x]} </label> </li> "; } private function voteLine($answer,$result,$votes) { echo "Answer: $answer"; echo "<br />"; echo "Result: $result"; echo "<br />"; echo "Votes: $votes"; echo "<br />"; echo "<br />"; $result = isset($result) ? $result : 0; $percent = round(($result/$votes)*100); $width = $percent * $this->scale; return " <li> <div class='result' style='width:{$width}px;'> </div>{$percent}% <label class='poll_results'> $answer </label> </li> "; } // remainder of script here ?> The ones that are returning blank a $result and $votes $results should be the number of votes a specific option has received while $votes is the total number of votes in the whole poll. My database contains the following data... QID AID votes 685b9628ca340529fa54208c65721dd7 2 205 685b9628ca340529fa54208c65721dd7 0 5 685b9628ca340529fa54208c65721dd7 1 2 It's from the following tutorial - http://net.tutsplus.com/tutorials/ph...poll-with-php/ Can anyone advise me here? Many thanks, Greens85 Hi I am adapting Jeffery Ways Mysql class to accept multiple where statements however I have got stuck on the final hurdle. It is when I try to do the bind_results() and I pass in the parameter types and the parameters. Here is that part of the code: if ($this->_where) $values = array_values($this->_where); $str = "'"; $str .= implode('\', \'', $values); $str .= "'"; // echo $str; $count = count($this->_where); foreach($this->_where as $key => $value){ $key = $value; } $user = 'matt25'; $pass = '6722853cacc4a9649dc75abc852f23c35b1f75cb'; $stmt->bind_param($this->_paramTypeList, $user, $pass); } It works how it is by setting the parameters as variables, but that obviously isn't practical. as you can see I also tried to make a string with the values from the array which brought up the error: Warning: mysqli_stmt::bind_param() [mysqli-stmt.bind-param]: Number of elements in type definition string doesn't match number of bind variables in C:\wamp\www\trick_tips\admin\includes\MysqlDb.php on line 260, the same as when I try to put the array into there. So I need some way of setting each value in the array as a variable to then put into the function, or another Idea that I have completely missed. Any help would be much appreciated. Cheers, Matt |