PHP - Echo Sql Result?
Hi guys,
Here's my code:
<?php $servername="127.0.0.1"; $username="root"; $password=""; $dbname="testdb"; $connection = new mysqli($servername,$username,$password,$dbname); $sql = "SELECT Wages FROM w WHERE \"Country\"=\"".$_POST["blah"]."\""; $r = $connection->query($sql); $result = $r->fetch_all(MYSQLI_ASSOC); echo $result; ?>When I go to the page I get the following message: Notice: Undefined index: w in C:\xampp\htdocs\test\processing.php on line 13 Does anyone know what problem I'm having here? /stuck Cheers, B Similar TutorialsI am getting the row results from mysql as called, but they appear as a straight line instead of new table row when I echo like: echo "TABLETABLETABLETABLE"; I am looking for: echo "TABLE TABLE TABLE TABLE"; Here is my code: Code: [Select] $brand = $_POST['brand']; $city = stripslashes($_POST['city']); $state = $_POST['state']; $zip_code = stripslashes($_POST['zip_code']); if($city !=""){ $query = "SELECT name, bus_type, street, city, state, zip_code, brand, quantity, price1, price2, date FROM `prices` WHERE city ='".$city."' AND state ='".$state."' AND brand = '".$brand."'"; }else{ $query = "SELECT name, bus_type, street, city, state, zip_code, brand, quantity, price1, price2, date FROM `prices` WHERE zip_code ='".$zip_code."'"; } $result = mysql_query($query); $count=mysql_num_rows($result); if($count==0 && $zip_code !=""){?> <td width="100%" class="style9">Sorry! There are no results for that city, state and brand.</td> <? }else{ while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ ?> <td width="100%" class="style9"><?php echo "<table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td{$typ_image}</td> <td><b><a href=\"\" title=\"{$row['street']} {$row['city']}, {$row['state']}. {$row['zip_code']}\" target=\"_blank\">{$row['name']}</a></b><br>Last Updated:{$row['date']}</td> <td><b>{$row['brand']} - {$row['quantity']}</b><br>Before Tax:\${$row['price1']} After Tax:\${$row['price2']}</td> <td{$pago}</td> </tr> </table><BR>"; ?></td> <?php } } ?></table> <p> </p> </td> Hi There, I have an SQL query that returns 10 rows, which I want to echo over 2 columns and 5 rows, however, I want rows 1-5 on the left hand column and rows 6-10 on the right hand side. Is there an easy way to do this? Normally I would do a fetch_array but, that would place the rows in order of, left, right, left, right - if that makes sense? Table is a standard table with 2 columns and 5 rows. Thanks Matt I am really lost here with this date issue of mine. The below code is the last part of a query: Code: [Select] $defendercheck_3 = $row_checkifattacked3['atdate']; $defendercheck1_3 = strtotime("$defendercheck_3"); $defendercheck2_3 = date("D", $defendercheck1_3); The query does not return any results as expected, but when echoing the various steps I get following: echo "$defendercheck3"; = nothing (as expected) echo "$defendercheck1_3"; = nothing (as expected) echo "$defendercheck2_3"; = result! (NOT expected) why does it return anything on "date("D", $defendercheck1_3)" when "$defendercheck1_3" is blank? OK, have no idea what's going on... I've done this a million times... why wont this output!?? I must have a major brain meltdown and dont know it yet!!! Code: [Select] <?php // this echoes just fine: echo $_POST['testfield']; // but this wont echo: echo if (isset($_POST['testfield'])) { $_POST['testfield'] = $test; } echo $test; /// or even this DOESNT echo either!: $_POST['testfield'] = $test; echo $test; ?> Hi All, I'm trying to echo the response from an SLA query, the query works and returns the data when I test it on an SQL application.. but when I run it on my webpage it won't echo the result. Please help? <?php $mysqli = mysqli_connect("removed", "removed", "removed", "removed"); $sql = "SELECT posts.message FROM posts INNER JOIN threads ON posts.pid=threads.firstpost WHERE threads.firstpost='1'"; $result = mysqli_query($mysqli, $sql); echo {$result['message']}; ?> I have a log system that allows 10 logs on each side(Left and right). I am trying to make it so that the left side has the 10 most recent logs, then the right as the next 10. Any ideas? So I need to echo a row from my database with php, but where i need to echo is already inside an echo. This is my part of my code: $con = mysql_connect("$host","$username","$password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("main", $con); $result = mysql_query("SELECT * FROM Vendor"); while($row = mysql_fetch_array($result)) { //I need to echo right here .................. but I get a blank page when I try this. Please Help. echo '<option value=$row['vendor_id']>'; echo $row['vendor_id']; echo '</option>'; } mysql_close($con); Result: A Blank page. Thanks in advance! Hi
I try to echo out random lines of a html file and want after submit password to whole content of the same html file. I have two Problems.
1st Problem When I echo out the random lines of the html file I don't get just the text but the code of the html file as well. I don't want that. I just want the text. How to do that?
for($x = 1;$x<=40;$x++) { $lines = file("$filename.html"); echo $lines[rand(0, count($lines)-1)]."<br>"; }I tried instead of "file("$filename.html");" "readfile("$filename.html");" But then I get the random lines plus the whole content. Is there anything else I can use instead of file so that I get the random lines of text without the html code?P.S file_get_contents doesn't work either have tried that one. 2nd Problem: As you could see in my first problem I have a file called $filename.html. After I submit the value of a password I want the whole content. But it is like the program did forget what $filename.html is. How can I make the program remember what $filename.html is? Or with other words how to get the whole content of the html file? My code: if($_POST['submitPasswordIT']){ if ($_POST['passIT']== $password ){ $my_file = file_get_contents("$filename.html"); echo $my_file; } else{ echo "You entered wrong password"; } }If the password isn't correct I get: You entered wrong password. If the password is correct I get nothing. I probably need to create a path to the file "$filename.html", but I don't know exactly how to do that. Basically I want this to do do is: if (there is no result found in the query){ echo "nothing for this brand"; }else{ echo this link; } this is my code...im just confused on what i want the if statement to to ask for. any help would be greatly appreciated Code: [Select] <?php $mypro = mysql_query("SELECT * FROM Sheet1 WHERE pro_catagory LIKE '%People%' ORDER BY pro_id DESC"); while($row=mysql_fetch_array($mypro)) { if(Not sure what to put here){ echo "There are no listings for the brand right now"; }else{ print "- <a href='proList.php?proNumber=".$row['pro_id']."'>".$row['pro_name']."</a><br />"; } } ?> Ok i call a function like so ... <?php PunchTime($monday,"in","1",$etime_who); ?> Below is the function, if you look closely i echo the query after it's been ran, and that query works 100% since i copied & pasted the query into the database and it returns a result that's needed. But for some bloody reason it doesn't work via code. function PunchTime($pdate,$type,$num,$ewho) { if($type == "in") { if($num == "1") { $etime_col = "PUNCH_IN"; } elseif($num == "2") { $etime_col = "PUNCH_IN2"; } } elseif($type == "out") { if($num == "1") { $etime_col = "PUNCH_OUT"; } elseif($num == "2") { $etime_col = "PUNCH_OUT2"; } } include_once('oracleCON.php'); $etime_qry = "SELECT $etime_col FROM tablename WHERE who= '$ewho' AND punch_date = '$pdate'"; echo $etime_qry; $etime_go = oci_parse($conn, $etime_qry); oci_execute($etime_go); $etime_res = oci_fetch_assoc($etime_go); $time = $etime_res[$etime_col]; if($time == "") $time = "--"; echo $time; } All i get are "--" even though some should return a time stamp. i have a game script and it's always bringing back the same result and i cant see why.. all i get when the script it ran is [/code]echo '<div class=noticeBox><h2>Sorry! No available member found![/code] the code is below and can provide the functions and db if needed, but cant see what's wrong. Code: [Select] <?php include '../header.php'; echo '<div id=AjaxSubDiv>'; echo '<div id="actionDiv">'; include '../statusbar.php'; echo '<div id=contentBox>'; // Show Fight Result if( !empty($_GET[action]) AND $_GET[action]=='attack' ) { echo $str; // Fight Lists echo '<P class=pageheader>Fight</P>'; echo '<P>Its time for action! Fight with rival thieves and grab their cash. You will require 1 strength for each fight and you will gain some cash and exp if you win the fight. However you will just earn some exp if you loose!! Each fight will decrease your health so keep an eye on health level because if your health goes below zero you will die and loose everything...</P>'; $res = query("SELECT COUNT(*) FROM `usertable` WHERE `userid`!=$user"); list($total) = mysql_fetch_array($res); if( $total>0 ) { $res = query("SELECT * FROM `usertable` WHERE `userid`!=$user LIMIT 0,20"); $viewplayer = Player::getById($row[userid]); echo '<tr>'; echo '<td width=120px>'; echo '<P class=titleP><a href="#" onclick="load_menu_val(\'AjaxSubDiv\', \'profile\', '.$row[userid].');return false;"><fb:profile-pic uid="'.$row[userid].'" size="square" linked="false" width="75px" class="userImg" /></a></P>'; echo '<P class=titleP><a href="#" onclick="load_menu_val(\'AjaxSubDiv\', \'profile\', '.$row[userid].');return false;"><fb:name uid="'.$row[userid].'" linked="false" /></a></P>'; echo '</td>'; echo '<td width=120px>'; echo '<P><B>Level:</B> '.$viewplayer->level.', '.get_level_title($player->level).'</P>'; echo '</td>'; echo '<td width=120px>'; echo '<P><B>Crew:</B> '.$viewplayer->crew.'</P>'; echo '</td>'; echo '<td width=300px>'; if( $viewplayer->health > 20 ) { echo '<form id="FightForm'.$row[userid].'" method="POST" class="itemForm">'; echo '<input type=hidden name=user value="'.$user.'">'; echo '<input type=hidden name=opid value="'.$row[userid].'">'; echo '<input type=hidden name=action value="dofight">'; echo '<P><input type=button onclick="do_submit(\'FightForm'.$row[userid].'\',\'http://www.bofs.us/thief/thiefmaster/fight/post_fight.php\', \'actionDiv\'); return false;" value="Fight Now" class="submitButton" /></P>'; echo '</form>'; } else { echo '<P class=titleP>Too Weak To Fight</P>'; } echo '</td>'; echo '</tr>'; } echo '</table>'; echo '</center>'; } else { echo '<div class=noticeBox><h2>Sorry! No available member found!</h2></div>'; print"$res"; } echo '</div>'; // end of contentBox echo '</div>'; // end of actiondiv echo '</div>'; // end of AjaxSubDiv ?> I'm writing an admin panel for my site (to manage users, etc) I selected the user-rights from the DB, but how can I check it the user-rights is equal to 3, and if it is allow access? at the moment i have my page: addevent.php i have written: Code: [Select] $q = "SELECT username " ."FROM ".TBL_USERS." ORDER BY ASC"; $result = $database->query($q); on the database.php page here is what query looks like: Quote /** * query - Performs the given query on the database and * returns the result, which may be false, true or a * resource identifier. */ function query($query){ return mysql_query($query, $this->connection); } then i want to display $result in a drop down menu so i wrote back on addevent.php: Code: [Select] <select name="Select1"> <option value="<? echo("$result"); ?>"><? echo("$result"); ?></option> </select> Basically the following code works fine, exepct when it comes to the last result it inserts it twice, example: (3,17),(4,17),(5,17),(5,17) Any clues as to why? Thanks Code: [Select] if(count($addIDs_ary) > 0) { $str = ""; foreach($addIDs_ary as $val) { $str .= "({$val},{$playerID}),"; if(end($addIDs_ary) == $val) { $str .= "({$val},{$playerID})"; } } echo $str; // (val,val), (val,val), (val,val) etc.. $query = "INSERT INTO hitlist (hit_id,player_id) values $str"; I have been looking at this code all day trying to find where I had results and didn't free them. Hopefully your eyes will have better luck. // if form is filled continue with script if($full == "TRUE"){ // function to concatinate two individuals string into one string function fullname($first, $last){ $fullname = "$first"." "."$last"; return $fullname; } $fullname = fullname($_POST['firstname'], $_POST['lastname']); // Check for existing user in rak5 $sql = "SELECT COUNT(*) FROM rak5 WHERE empid = '$_POST[empid]' AND fullname = '$fullname'"; $rakfcheck = mysql_query($sql); if (@mysql_result($rakfcheck,0,0) > 0) { mysql_free_result($rakfcheck); // check uaid in user table $sql = "SELECT COUNT(*) FROM user WHERE UAID = '$_POST[UAID]'"; $UAIDcheck = mysql_query($sql); //if UAID is in the user table then check employee id for redundancy if(@mysql_result($UAIDcheck,0,0) > 0){ mysql_free_result($UAIDcheck); $sql = "SELECT COUNT(*) FROM user WHERE UAID = '$_POST[UAID]' AND employeeID = '$_POST[empid]'"; $UAID_Empcheck = mysql_query($sql); //if there is a UAID emplid match on the user table print redundancy //else UAID is occupied by another user mysql_free_result($UAID_Empcheck); error(' Employee already has a UAID!'); } else { error('UAID is currently active by a different employee'); } } //UAID is not in the user table else{ $newpass = substr(md5($_POST['empid']),0,6); //insert new user $sql = "INSERT INTO user SET userid = '', firstname = '$_POST[firstname]', lastname = '$_POST[lastname]', email = '$_POST[newemail]', notes = '', password = ('$newpass'), UAID = '$_POST[UAID]', BOG = '', employeeID = '$_POST[empid]'"; $result = mysql_query($sql); // Email the new password to the person. $message = "G'Day! Your personal account for the Project Web Site has been created! To log in, proceed to the following address: http://ciwdvweb1.itd/web2/test2/index.php Your personal login ID and password are as follows: userid: $_POST[UAID] password: $newpass You aren't stuck with this password! Your can change it at any time after you have logged in. If you have any problems, feel free to contact me at Security Front End GUI creator "; $umail = $_POST['newemail']; mail($umail,"UAID and password", $message, "From: <you@example.com>"); include "MoveOn.html"; } } else{ error('either the name or employee id entered is incorrect please resubmit'); } } else { error('Please fill out the whole form'); } mysql_close(); endif; ?> I was wondering if it was my INSERT query but I tried to save the query into a variable and free it but I got another warning saying the variable wasn't the right parameter. Thank you for your help Hello all. I am using a premade login script which has some very powerful function built in, the one I am looking at using is as follows:
/** * query - Performs the given query on the database and * returns the result, which may be false, true or a * resource identifier. */ function query($query){ return mysqli_query( $this->connection, $query); }The issue is, displaying the results. I call is via the following code: $database->query('SELECT LastName, Firstname FROM Patrons WHERE LastName = "Delude"');But I have no idea how to display it. I have attempted to echo it out, but I get the following error in the logs: PHP Catchable fatal error: Object of class mysqli_result could not be converted to string Hello all, I'm struggling adding a count result to this script. I want each result to be an id so I can place x amountof images in one position and the remaining in another position. Each user might have different awards so just using the award_id is no good as there will be empty space so I need the actual result to display a id number. Code: [Select] $res = mysql_query("SELECT award, image FROM awards WHERE active = '1'"); $codes = array(); while ($row = mysql_fetch_assoc($res)){ $codes[$row['award']] = $row['image']; } $userid = '1'; $res = mysql_query("SELECT * FROM user_awards WHERE user_id = '$userid'"); $row = mysql_fetch_assoc($res); foreach ($codes as $award => $image){ if ($row[$award] == 1){ echo "<img src=../$image><br/>"; } } Hi, I was wondering if I wanted lets say 3 to the power of 10 how can I do this in php? I searched a few places for some power to operator in PHP but no luck could some one tell me thanks? Hello, everyone. I am having some trouble figuring this out. I am trying to create a paging bar(so to speak) to display results by page number. Trying to get the paging bar to go as follows... Requested Page The resulting paging bar Page 1 1 2 3 4 5 Page 2 1 2 3 4 5 Page 3 1 2 3 4 5 Page 4 1 2 3 4 5 Page 5 4 5 6 7 8 Page 6 4 5 6 7 8 Page 7 4 5 6 7 8 Page 8 7 8 9 10 11 ...... This is what I have right now that I am trying to get to work. I have changed this so many times and been working on it for 2 days. I think I'm just confusing my self. This can't be that hard.. Code: [Select] <?php echo '<html>'; //---these values changed based on query---- $Page=$_GET["page"]; //the page number requested $AvailablePages=5; //number of pages available after the page requested //---calculations--- $StartPage=round($Page/5)*5; $EndPage=ceil($StartPage/5)*5 ; //the last page number to be displayed in paging if($StartPage<5) {$StartPage=1;} //just looking at variables echo 'page is: ' . $Page . '<br>'; echo '<br>Starting @: ' . $StartPage; echo '<br>Ending @: ' . $EndPage . '<br>'; //--create the paging bar-- $PagingBar=''; while($StartPage<=$EndPage) { if($Page==$StartPage) { $PagingBar=$PagingBar . $StartPage . ''; } else { $PagingBar=$PagingBar . ' <a href="test.php?page=' . $StartPage . '">' . $StartPage . '</a> '; } $StartPage++; } //---show the paging bar-- echo $PagingBar; echo '</html>'; ?> Hey everybody, i'm building a website for the softball league i play in.... so far the website is pretty good... with all the stats and profiles.... i'm having a little problem with the ORDER of the leaders in the categories i have to calculate the result... for example... avg. is the result of the total hits divided by the total number of at bats... both numbers are coming from the database... the problem comes when i have to order the leaders from first to last... this is my php: Code: [Select] $sql = "select profile_id, SUM(total_hits) AS hitstotal, SUM(ab) AS abtotal from batters WHERE year = '2010' GROUP BY profile_id"; $cons = mysql_query($sql); while ($result = mysql_fetch_array($cons)) { $sumaab = $resultad['abtotal']; $sumahits = $resultad['hitstotal']; $p_id = $resultad['profile_id']; $prom = round(($sumahits."") / ($sumaab.""),3); that gives me all the batting averages for the players. and here is my question: how can i order that $prom result from first to last? |