PHP - Not Displaying First Result
i have it set up so the user picks the year and session and then the database shows all the games in that specific year and session and then displays them with a link to their photo galleria and also shows the record(wins - losses - ties) but the way i have it know its not displaying the first result here is the code
Code: [Select] <?php //declares $y as year played and $s as session $y = ' '; $s = ' '; //handles submition of form for picking year and session if (isset($_POST['submit'])) { $data = mysql_real_escape_string($_POST['session']); $exploeded = explode(",", $data); $y = $exploeded[0]; $s = $exploeded[1]; } //Query for the selection menu $squery = "SELECT DISTINCT(Year_Played), Sessions FROM pinkpanther_games"; $sresults = mysql_query($squery) or die("squery failed ($squery) - " . mysql_error()); //checks $y and $s to see if their is a vaule if ($y == ' '){$y = '20112012';} if ($s == ' '){$s = '2';} //Query for getting record and for getting all the appropriate info for displaying the games $query = " SELECT (SELECT COUNT(id) FROM pinkpanther_games WHERE Year_Played = $y AND Sessions = $s AND Win_Loss = 'Tie' ) AS 'Tie', (SELECT COUNT(id) FROM pinkpanther_games WHERE Year_Played = $y AND Sessions = $s AND Win_Loss = 'Win') AS 'Win', (SELECT COUNT(id) FROM pinkpanther_games WHERE Year_Played = $y AND Sessions = $s AND Win_Loss = 'Loss') AS 'Lose', Opponent AS Opponent, Score AS Score, Gallery_no AS Gal, Win_Loss AS Record FROM pinkpanther_games WHERE Year_Played = $y AND Sessions = $s"; $results = mysql_query($query) or die("Query failed ($query) - " . mysql_error()); $row_a = mysql_fetch_assoc($results); //Set record variables $wins = $row_a['Win']; $loss = $row_a['Lose']; $tie = $row_a['Tie']; //creates from and selection menu for year and session echo "<tr><td colspan='2'><form method='post' action=''><select name='session' class='txtbox2'>"; while ($srow = mysql_fetch_assoc($sresults)){ echo "<option value='" . $srow['Year_Played'] . "," . $srow['Sessions'] . "'>" . $srow['Year_Played'] . " Session " . $srow['Sessions'] . "</option>"; } echo "</select><input type='submit' name='submit' value='Go' class='txtbox2' /></form></td></tr>"; //displays record echo "<tr><td colspan='2'>" .$wins . " - " . $loss . " - " . $tie . "</td></tr>"; echo "<tr></tr>"; //displays games and scores in appropriate year and session while ($row = mysql_fetch_assoc($results)){ $opp = $row['Opponent']; $score = $row['Score']; $gal = $row['Gal']; $wlt = $row['Record']; //styles games acording to if win lose or tie if ($wlt == 'Win'){ echo "<tr><td class='win'>"; echo "<a href='galleries.php?g=$gal'" . $gal . " >" . $opp . "</a>"; echo "</td><td class='win'>"; echo $score . ""; echo "</td></tr>"; } if ($wlt == 'Loss'){ echo "<tr><td class='loss'>"; echo "<a href='galleries.php?g=$gal'" . $gal . " >" . $opp . "</a>"; echo "</td><td class='loss'>"; echo $score . ""; echo "</td></tr>"; } if ($wlt == 'Tie'){ echo "<tr><td class='tie'>"; echo "<a href='galleries.php?g=$gal'" . $gal . " >" . $opp . "</a>"; echo "</td><td class='tie'>"; echo $score . ""; echo "</td></tr>"; } } ?> Similar Tutorialsi cannot figure out why my first result is not displaying properly it successfully shows all results but me first myurl.com/other.php?id=2 now showing any thing kindly help to solved this problem! it seems like problem is in variable $http$ids but dunno how to combine them to get result $Ids always b numeric number <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); $http = "myurl.com/other.php?id=" ; $conn=odbc_connect('greeting','',''); if (!$conn) {exit("Connection Failed: " . $conn);} $sql="SELECT * FROM mytable"; $rs=odbc_exec($conn,$sql); if (!$rs) {exit("Error in SQL");} echo "<table border= 1><tr>"; echo "<th>ID</th>"; echo "<th>Like</th>"; echo "<th>title</th></tr>"; while (odbc_fetch_row($rs)) { $ids=odbc_result($rs,"ID"); $title=odbc_result($rs,"title"); echo "<tr><td>$ids</td>"; echo "<td><fb:like href=\"$http$ids\" layout=\"button_count\" show_faces=\"false\" width=\"100\" font=\"tahoma\" colorscheme=\"dark\"></fb:like> </td>"; echo "<td>$title</td></tr>"; } echo "</table>"; odbc_close($conn); ?> Hi! I want the image of my site to be clickable so that it shows the next image contained in the result set of the sql query. Code: [Select] <?php require_once('includes/connection.inc.php'); $conn = dbConnect(); $sql = 'SELECT filename FROM images ORDER BY image_id DESC LIMIT 1'; $msg = ''; if(!$sql) { echo "Something went wrong with the query. Please try again."; } $result = $conn->query($sql) or die(mysqli_error()); if(mysqli_num_rows($result) == 0) { header('Location: empty_blog.php'); $conn->close(); } else { $row = $result->fetch_row(); $image = $row[0]; } ?> <?php include('header.php'); ?> <div class="content main"> <img id="image" src="images/<?php echo $image; ?>"/> </div> <?php include('includes/footer.inc.php'); ?> All the filenames of the images are contained correctly in the $result variable, all I need to do now is to fetch the next image in the set. How would I go about this? Any help is greatly appreciated! Hello! I am busy developing a script that returns all users that have the cell "Available" set to 1 but I am unsure how to do this, I am familiar with basic SQL and I have made this: $sql = "SELECT * FROM `clans` WHERE `available` =1 LIMIT 0 , 30"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); echo ($row['name']); but it only displays information from the first row found, and I want it to display all the rows found, how can I do this? Thanks - GreenFanta Hi, I am new to php but not to programming. I created a script on a windows platform which connects to the mysql database and returns the results of a table. A very basic script which I wrote to simply test my connection worked. The script works fine on my windows machine but not on my new mac. On the mac it simply does not display any records at all. I know that the database connection has been established because there is no error but I can not see why the result set is not being displayed on screen, as I said it worked fine on my windows machine. The Mac has mysql (with data) and apache running for php. Please could someone help as I have no idea what to do now? Script below: Code: [Select] $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'root'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'test'; mysql_select_db($dbname); mysql_select_db("test", $conn); $result = mysql_query("SELECT * FROM new_table"); while($row = mysql_fetch_array($result)) { echo $row['test1'] . " " . $row['test2'] . " " . $row['test3']; echo "<br />"; } mysql_close($con); Hi I am building a product search engine using MySql and PHP (Jquery / AJAX). As i am getting the search results i wondered is it possible to count the instances of a category? For example: If i search for "Dell Laptops" i get 400+ results back because it has lots of laptops and accessories. What i am aiming for it to do is while looping through look at the categories and if its the first instanc eof it i want it to begin a count. until it has finished looping and then i can display it. Results: 436 [ Laptops(127) - Accesories (244) - Components(65) ] Im not even sure where to start here so any advice will be helpful Here is the code im using to generate the search: $id = str_replace(" ", "%", "$id"); $q = "SELECT * FROM products WHERE prod_name LIKE '%$id%' order by fee asc LIMIT 20"; Hello all,
Am trying to calculate some data and display the result of the current month in a chart form. i just don't know how to get the current month. this is not working..
<?php include('mysql_connect.php'); $date = 'MONTH(CURRENT_DATE())'; $status = 'paid'; //mysql_select_db("hyprops", $con); $query = mysql_query("SELECT sum(amount) 'amount', department FROM requisition WHERE status = '$status' AND date='$date' "); $category = array(); $category['name'] = 'department'; //$series1 = array(); //$series1['name'] = 'actual'; $series2 = array(); $series2['name'] = 'amount'; //$series3 = array(); //$series3['name'] = 'Highcharts'; while($r = mysql_fetch_array($query)) { $category['data'][] = $r['department']; // $series1['data'][] = $r['actual']; $series2['data'][] = $r['amount']; // $series3['data'][] = $r['highcharts']; } $result = array(); array_push($result,$category); //array_push($result,$series1); array_push($result,$series2); //array_push($result,$series3); print json_encode($result, JSON_NUMERIC_CHECK); mysql_close($con); ?>Please how can i solve this issue? Thanks in advance Hello - Suppose I had a MySQL result set that was something like this: ITEM: COLOR: ball red ball blue book red book green book black If I were to use the code: Code: [Select] do { echo $row_myQuery['item'] . " - " . echo $row_myQuery['color'] . "<br />"; } while ($row_myQuery= mysql_fetch_assoc($myQuery)); Then I end up with this: Code: [Select] ball - red ball - blue book - red book - green book - black MY QUESTION: What I'd like to know is, how could I re-write that php code so that I could get an output like this?: Code: [Select] ball - red, blue book - red, green, black Thanks! This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=330221.0 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? 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> 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 ?> 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. 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 />"; } } ?> 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? i have two tables, and i want to display data from the most recent entry of the two(i.e. display just one entry). i'm joining together 2 tables so that i can get this entry.Both tables contain the date, so i'm ordering the results of the query so that the most recent comes first. My tables a TOPIC topic_id topic _name section_sub_id date POST post_id post_name section_sub_id date I'm using the following code to get the last result, but nothing is being echoed $join =mysql_query("SELECT topic.*, post.* FROM topic LEFT JOIN post ON topic.section_sub_id=post.section_sub_id WHERE post.section_sub_id = " .$row2['section_sub_id']. " ORDER BY topic.date") or die("Select Error :" . mysql_error()); $latest= mysql_fetch_row($join); echo $latest['post.date']; i'm not sure if there is something wrong with the sql, or with the php. ANy help would be great Need some help on my result counter. I am using a search box to return data from my database i can get the result returned fine but i am having problems getting the total number of result returned. It only returns the number of results per page as i am using a paginate. Can some one point me in the right direction. The number count im using is below. Code: [Select] $num_rows = mysql_num_rows($sql); echo "$num_rows Results Found\n"; 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/>'; } ?> statez : I need to sort the results from the high score to the low score. $query = "SELECT statez, COUNT(statez)FROM distributors GROUP BY statez"; $results = mysql_query($query); $returnS=""; while($line = mysql_fetch_array($results)) { $returnS.= $line['COUNT(statez)'].",,".$line['statez'].",,,"; } echo $returnS; mysql_close($link); ?> 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 Hi i got a search form and when im searhing for result i get nothing. i got 5 search fields : 1. Erea 2. category 3. subcategory 4. from price 5. to price if im not specifieing from price and to price i get blank result ,if i do specify the from price to price ,then i get the results. this is the code im using to get the results. Code: [Select] $sql=mysql_query("select * from posts where erea = '$erea' and category = '$category' and sub_category = '$subcategory' and price >= '$fromprice' and price <= '$toprice'"); what i want is to get the result even if i didnt specify the price from, to . thanx |