Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    PHP


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Query Not Returning First Result


I have a query that is returning the correct number of rows. However, when I try to print the rows out, it will not print the first row, but all after that. I can't figure out why it isn't printing out the first row, even though the query is returning the results. Here is my code below to print the results in a table: Any suggestions?

while($row2 = mysql_fetch_array($result1))
{
$affinity_name = $row2['affinity_name'];
$affinity_detail = $row2['affinity_detail'];
$affinity_no = $row2['affinity_name'];
$track_id = $row2['id'];
get_name($affinity_name);

$affinity_details .=<<<EOD
<tr>
<td><a href="/m_t5.php?affinity_id=$affinity_no&q=$name">$name</a></td>
<td>$affinity_detail</td>
<td><a href="/delete_track.php?track_id=$track_id">Delete</a></td>
</tr>
EOD;
}




View Complete Forum Thread with Replies

Related Forum Messages:
$result = $stmnt->fetchAll(); Returning Duplicate Keys For A Single Query
For some reason when I do a fetchall on a PDO query the array returned
has duplicated keys. see below.

View Replies !
Returning 1 Result From MySQL
I know the usual way of receiving results from MySQL, useing a while loop e.g.

$sql = "SELECT * FROM users WHERE email='joe@hotmail.com'";
$result = mysql_query($sql,$connection);
while ($row = mysql_fetch_array($result)){
echo $row["firstname"];
echo $row["lastname"];
echo $row["email"];}

BUT, if I know they only 1 result is going to be returned, is there a way to do this without using a while loop? So if I only wanted to get only the firstname of the person with email joe@hotmail.com. can I do this without a while loop or do I have to use one?

View Replies !
NO Error - But Returning No Result
Basically I have two tables, one for news, and one for results. I am doing a

SELECT * FROM `news` AS t1, `news_comments` AS t2 WHERE t1.id = t2.newsid ORDER BY t1.date DESC, t1.id DESC, t2.com_datetime DESC

query, and to start off with I already had comments I had inserted manually, it worked PERFECTLY! That was until of course, I deleted all of the comments, then I get absolutely no result from this query.

Is there any way to get round this, where it still returns results even if there are no comments.

View Replies !
Script Not Returning Correct Numerical Result
I am working on a script to calculate returns on bets. This involves entering odds, stake etc. The problem I am having is with adding a new element into the calculation. In betting their is something called a Rule 4. This occurs in some races and diminsihes the retrun but there is no need to go into details.

Basically, here is how it works: There is a race with odds of 2/1 and a rule 4 of 20 cents is in place. With the betting rules this means that the odds must be multiplied by 1 - rule 4. In this case the rule 4 is .20 so 1 - .20 = .80 You now have to mulpiply the odds by .80 We only multiply the first number os in the case that is 2 (for a 5/1 bet it would be 5 etc)

.80 * 2 = 1.6 is the correct answer. This calculates ok in part of my script but when it gets to the second part on the same page it is returning 1.28 instead. PHP Code:

View Replies !
Code Returning False Mysql Result
I'm working on code which will allow users to "rate" something, for instance, on a scale of 1-5. When they click on a star (1-5), it sends them to the following PHP script, with ?rid=&rating=

rid is the id of the item they are rating, and rating is the integer 1, 2, 3, 4, or 5. Problem is... even with an empty db table, it returns "Rating added successfully." - but doesn't add anything. If I add a row with uid=1 rid=2 and rating=3, and am logged in as uid=1, it still says "Rating added successfully.", and does nothing. It SHOULD HAVE updated the existing row and told me so. Code:

View Replies !
Pass Conditions From 4 Fields Before Returning The Result.
im doing a search query, whereby it'll have to satisfy a few conditions. as it's very straightforward it'll need to pass conditions from 4 fields before returning the result. i've made use of a temporary table. thing is, i could return it using one condition, but it gives a msg saying query unbuffered when i tried with all 4.

$result = mysql_query("SELECT * FROM PEAR_reports WHERE trainer='$trainer1' AND program_title='$program_title1' AND start_date='$start_date1' AND end_date='$end_date1'");

anything wrong or funny with that line?

View Replies !
Returning Result Set (many Rows) From MySQL Stored Procedure
I have a MySql stored procedure that simply runs a SELECT that will return multiple rows. I'm calling it using PEAR::Db->query. I get an error return:

[nativecode=1312 ** PROCEDURE neighborhoodserver.proc_Get_available can't return a result set in the given context]'

If I simply execute the SELECT statement through 'Db->query', it works fine. If I call the stored procedure from the command line, it works fine.

What am I missing?

View Replies !
Turn Select Query Result Into Hyperlink To Other Query
I have a query which gives results of selecting coursenames from a table called trainingtopics but this does so in a continuous bulk of text without any breaks between each record. my question how do I create line breaks between each record and also how can I force each query result to become a hyperlink which when clicked runs another query that gives details of that course.

<?php
$user = "root";
$host = "localhost";
$password = "";
$connection = mysql_connect($host, $root, $password) or die ("Couldn't connect to server.");
$database = "courses";
$db = mysql_select_db($database) or die ("Couldn't select database.");

$sql = "SELECT coursename FROM trainingtopics";
echo $sql."=sql<br>";

$result = mysql_query($sql) or die(mysql_error());
echo $result."=result<br>";

while($row=mysql_fetch_array($result))
{ // NOTE this one ABOVE the echo
echo "result found!";
echo $row[0];
}
?>

View Replies !
Query Returning Array
I'm missing something very obvious, but it is getting late and I've
stared at it too long.

I am writing a basic function (listed at the bottom of this post) that
returns data from a query into an array.

The intent is that the following code:
$foo = dbSelectData("SELECT foo, bar FROM table", $link);
would return an array with the keys: 'foo' and 'bar'.

But what I get is instead a multidimensional array.
Doing a var_dump on $foo turns out to be
array(2) {
["foo"]=>
string(5) "Stuff"
["bar"]=>
string(10) "More Stuff"
}

I'm wondering where I went wrong in writing the function below.

function dbSelectData($query, $connection, $rtype=MYSQL_ASSOC){

$result = mysql_query($query, $connection);
if(!$result){
dbThrowError("Error in function dbSelectData. Query Was <em>
$query</em>.");
return FALSE;
}
else{
$numrows = mysql_num_rows($result);

if($numrows == 0){
return FALSE;
}
else{
while($rows = mysql_fetch_array($result, $rtype)){
$output[] = $rows;
}
mysql_free_result($result);
return $output;
}
}
}

View Replies !
Query Returning NULL
Trying to get a percentage (ROUND) off of two SUM columns but everything I try does not work. Is this even possible? The query I am trying: PHP Code:

SELECT players.id, players.fname, players.lname, teams.name,
player_stats.team_id, divisions.name,
ROUND( ( 1.00 - ( SUM( player_stats.goalsa ) / SUM( player_stats.shotsa ) ) ) , 3 )
AS total_svp

Trying to get SUM of both goalsa and shotsa, divide goalsa by shotsa, subtract that from 1.00, and ROUND that to 2 decimals. I can do it in PHP no problem, but am hoping to save some time by doing the calculation in the query.

View Replies !
Query Not Returning Results
I'm trying to prevent username duplication upon registering into a database. What I have in my PHP is....

$conn = dbConnect();
$sql = 'SELECT * FROM `tbl_users` WHERE `user` = ' . $_POST[ 'user' ];
$userCheck = $conn -> query( $sql );
if ( mysqli_num_rows( $usercheck ) != 0 ) {
$result .= 'Username is already in use choose another one' . '<br />'
$errors += 1;
}

The dbConnect(); function is working properly, but I'm not getting any rows in $userCheck.
here's the specific error:

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in C:wampwwwfastimportscontent
egister.php on line 30

I purposely tried to add a username that was already in the database, so is it a problem with my query? possibly datatypes? The $_POST[ 'user' ] as you might have guessed comes from a text-type input box. I also wanted to check to see if I could convert to upper to check regardless of case.

View Replies !
Query Is Returning 0 Results
i thought i had this working earlier. I tested this in phpmyadmin and it worked fine. PHP Code:

//Would be sent from flash, used for testing
$theID="(letID=4)+(letID=60)+(letID=61)+(letID=3)+(letID=5)+(letID=6)";
$query = "SELECT * FROM scLets WHERE '$theID'";
$result = mysql_query($query);
if (!$result) {
    fail("Couldn't list Lets from database");
}
$letCount = mysql_num_rows($result);

$letCount returns 0. But if i do it this way. PHP Code:

$query = "SELECT * FROM scLets WHERE (letID=4)+(letID=60)+(letID=61)+ (letID=3)+(letID=5)+(letID=6)";
$result = mysql_query($query);
if (!$result) {
.......................

View Replies !
Query Not Returning Data
I'm trying to return information on a certain "family" or clan and the string my query returns is empty. Below is the familyinfo.php page which calls the function and below that is the function from database.php. Code:

View Replies !
Speeding Up Query/code (query Within Result Set)
I'm looking for ideas on how to speed up this script. Basically it finds all the zip codes in a zipcode table, then looks for all the records in another table with those zip codes.

Right now it finds all the zips then within that WHILE, it looks for a record in another table with that zip: PHP Code:

View Replies !
Sql Query Not Returning Correct Results
i'm using an entry in an sql database as a semaphore and it,
unfortunately, doesn't appear to be working. the script that spawns
the child processes has a for loop that performs the same basic sql
query over and over again until the value has changed (there's a one
second delay between each query). unfortunately, the resultant row is
always the same, even when the other process *has* changed it. as an
example, if the orig. value was of the entry was 0, and one second into
the execution of the second process, the entry was changed to 1, my
program would, even 10 seconds later, fetch 0. in other words, it'd
never be aware of the change.

any idea as to why this is and what i can do to fix it?

View Replies !
MySQL Query Not Returning All Results
I have a user table in the DB, for example:

+---------+----------------+-------------------+
|     uid     |     username     |       firstname       |
|----------+----------------+------------------+
|       1     |       cobby        |       Andrew          |
|       2     |       admini        |     test-account    |
+---------+-----------------+------------------+

If, in phpMyAdmin, I query:
   SELECT `username` FROM `users`;

It will return results correctly (cobby and admini, respectively).
But if I make a simple PHP script, such as:

<?php

mysql_connect('localhost', 'cobby', 'dbpass');
mysql_select_db('testdb');

$query  = mysql_query('SELECT `username` FROM `users`');
print_r(mysql_fetch_assoc($query));

?>

It only returns:
Array ( [username] => admini )

Why does it only return the second result? I have a feeling I'm doing something really silly, but I looked over this test script and its got me stumped.

View Replies !
Mysql Query Returning Incorrectly
The following MySql Query is not retuning correctly. It is returning dates outside the given range. Why? Code:

SELECT distinct
sale_type_landsale.sale_type_landsale_id
,sale_type_landsale.sale_date,sale_type_landsale.city,sale_type_landsale.name,sale_type_landsale.sale_price,sale_type_landsale.number_lots
FROM
sale_type_landsale
Left Outer Join connector_sale ON sale_type_landsale.sale_type_landsale_id = connector_sale.ref_id
Left Outer Join sale ON connector_sale.sale_id = sale.sale_id
Where
sale_type_landsale.sale_date >= &#55614;&#57158;-01-01'
AND sale_type_landsale.sale_date <= &#55614;&#57159;-06-08'
AND sale_type_landsale.city =&#394;'
OR sale_type_landsale.city =&#3913;'
AND connector_sale.ref = 'sale_type_landsale'
AND sale.sale_archive <> 1

View Replies !
Use Query Result Field As Query Key For New Query..
$query  = "SELECT ProjID, UserID, ProjDesc, file, OrigProj, OrigUser, ProjDate FROM projects";
$result = mysql_query($query);

I would like to take the field 'UserID', and utilise it for a Query statement to my users table in my database, to read and fill in information to my table, which looks like this:
PHP Code:

View Replies !
MySQL Query Returning Empty Column
Here's my code:

$query_get_machine = sprintf("SELECT machines.ID, machines.NotifyID, machines.Name, notify.ID, notify.`Data` FROM machines RIGHT JOIN notify ON machines.notifyID = notify.ID WHERE machines.ID = %s", GetSQLValueString($colname_get_machine, "int"));

Can anyone tell why the notify.`Data` column might be returned empty? All others display as they should.

View Replies !
Returning Incorrect Results From A Query Using MSSQL
I'm having a peculiar problem where PHP is occasionally returning incorrect results on a query. I'm connecting to the db like so: Code:

View Replies !
Select Query In Function Not Returning Content?
My connection works, my script runs without errors, warnings, etc, but the content that should be found from this function isn't coming through to the output? Code:

View Replies !
Execute The Query It Is Only Returning The Text Representation Of The Variable.
I am building a mysql query dynamically but when it comes time to execute the query it is only returning the text representation of the variable. I have the following code:

View Replies !
Returning Results Of Query Into Alternating Table Cells
I am pulling results from a query into my page & am trying to get the results into a table that is 2 columns wide. I am also alternating the background color from row to row.

I can get the results to alternate the background using the ternary operator, but am having trouble getting the records to echo correctly. It is obviously easy to get the records to just show a single record in each table row, but getting it to show 2 in one row & then continue on in the next row seems trickier. Code:

View Replies !
Using Query Result To Do Another Query In Loop
I have 2 tables, one called users2 and one called books. Books has a field called UserId, which is the ID of the user that added the book to the database.

My problem, is that i need to take this ID from the book table, and use it to get some information from the user table. Here is my code to get the ID from the book table: Code:

View Replies !
MySQL Query Not Returning Values Based On Date Correctly
I am trying to use a MySQL query that searches the database and only returns results during a specific time frame. And it is giving me articles that are not correct. Code:

View Replies !
Result From A Sql Query
Is there anyway I can exclude just one result from the database based upon the value of a field, for example i want to exclude the field with an ID of 1 but get all the other fields in the database. is this possible and can anyone tell me how? PS: I had thought about doing something like

$query1 = mysql_query("SELECT * FROM table ORDER BY id ASC");

while ($row = mysql_fetch_array($query1,MYSQL_ASSOC))
{
$id = $row['id'];
if ($id == 1)
{
//DO NOT DISPLAY ITEM
}
else
{
//DISPLAY ALL OTHER ITEMS
}
}

View Replies !
Result For Query
I dont know why this query is not returning a value, when I should be getting the value of &#3915;'. PHP Code:

mysql_select_db($dbname, $conn) or die (mysql_error());
    $query = "SELECT MIN(q_id) FROM questions2 WHERE quiz_id='".$quiz_id."'";
    echo $query.'<br />'
        $result = mysql_query($query) or die(mysql_error());
            $row = mysql_fetch_array($result) or die(mysql_error());
                $first = $row['q_id'];
                echo 'first='.$first.'<br />'

View Replies !
Query Result = Resource ID #10
I have an array $countertop.... i run through each one like this.
PHP Code:

View Replies !
Query Result In A Mail!
How do I insert a query result in a mail()? PHP Code:

View Replies !
Linked Result From A Query
I'm trying to create a query that will return a linked record from a
database that will take me back to an update page with that record so I

can change things in the record.

I'm having trouble finding simple code to do this.

View Replies !
Echo A $result Of Query?
Trying to have an echo display a result from a query. Not such a hard concept. Yet I am having trouble. What good is the data without analysis. Here is what I am using to try and grab result. Have been told it looks correct, must be missing something small.
When this runs, alternate echo displays in browser. So you know: 'testdata' is the table 'score' & 'id' are columns or fields.

Almost think it is missing a table structure to display in. Looking for player name column and score column (for the sake of example). Code:

View Replies !
Paging Of Query Result
This script used to be working in splitting query result into pages. But now, PREV 1 2 3 4 NEXT links is not working anymore. Any idea how to fix this ? or what is wrong with this script ? Code:

View Replies !
How To Select One Row From Query Result
once the button is clicked to find an appointment the following query is executed: Code:

View Replies !
Populate Result Query
I query database and it produces rows of results. I want to populate it so that the first 10 rows go to the 1st page, the next 10 rows to the 2nd page and so on. The last page will be at most 10 rows and it can be less than that. How do I do it? Or do anybody know if there is any sample code that I can refer to?

View Replies !
Filtering In Query Result With WHERE
I am trying to filter out records in a query using WHERE expressions. See example below.

if ($league="All") {$leaguebool="1"} else {$leaguebool="League='$league'"};
$query = "SELECT League,HR FROM ranfranbattingsim WHERE ('$leaguebool') ORDER BY $sorder DESC LIMIT $limit";

My desire is to select all records if $league='All' and select only records where LEAGUE=$league if $league is anything other than 'All'. LEAGUE is one of the fields of the database. I hope that I explained that well enough. I am open to any solutions, and have considered that perhaps I should be using something other than the WHERE statement to filter the records.

View Replies !
One Row Result Database Query
Most of the pages I write are multi-row queries. I have about 30 pages that will only yield one row of about 15 columns. What is the best way to design this page?

Right now, I am using $row = mysql_fetch_object($results) - this is causing a minor issue with positive/negative signs with numbers.

View Replies !
Not Able To Grab 1st Result Of Query
I am having an issue, when I run my query (shown below) directly in MS SQL it returns the first row (home.php / 323 hits), along with the rest. Code:

View Replies !
If Query Result Returns Nothing
i have a marquee which scrolls across news items, all this is database driven, however if no news items are returns from the query, my page errors, can someone help me write an else statement or something so that the page doesn't error. my code is below:-

<?php

require('database3.php');

if(!isset($news_item))
$news_item=''

$query = "select * from monksc.news where DATE_SUB(CURDATE(),INTERVAL 14 DAY) <= startDate order by id";

$result = mysql_query ($query) or die (mysql_error());

if (mysql_num_rows($result)>0)
..............

View Replies !
Displaying Result Of A Sum Query:
$sql = "SELECT sum(value) FROM `offers' WHERE sid='$sid'";
$result = mysql_query($sql);

As you can see, I'm trying to select a column in my database which is named "value" I want to return the sum of the records which match the current user's subscriber id ($sid) I think the query is structured correctly.

However, I'm having trouble placing the result of the query into a variable that php can echo to the page. In the database, the numbers are formatted as decimal. I just want to get the sum of the fields into a numeric php variable that I can add/subtract/divide etc and echo to the page. How do I go about doing this?

View Replies !
Mysql Query Result
I have successfully selected 4 rows using a mysql SELECT query. However, I would like to random pick a row from this result so that every page refresh will yield something different.

View Replies !
Weird Query Result
I am trying to do a simple query, but instead of a numeric value, I get "Resource id #34".

$newdodgemod1 = "select default_dodgemod from phpbb_classes where class='$newclass'";
$newdodgemod2 = $db->sql_query($newdodgemod1);

Any idea what is wrong with the code? All field exist and the variables are set correctly. I don't understand why I am getting this error.

View Replies !
Query Result To Array
i have a table with two field ID and CAPACITY. i want the ID to point to the capacity on an array

$top = "SELECT * from topics";
$db = new mysqli('localhost','root',?');
$db -> select_db('testing');

$res_top = $db->query($top);
$topics = array();
while ($row = $res_top->fetch_row())
{
$topics[$row['id']] = $row['capacity'];
}

View Replies !
Query Result Values
i have two tables a customer and package table. a customer can have many packages. how i can i set a status in the customer table to 'complete' if all the packages in the package table that relate to that customer are set to 'paid'? i can do a simple select statement but how will i know if all the status rows returned from packages are set to 'paid'.

View Replies !
Searching A Query Result
I have a simple query that selects everything from a database and limits the results to one row ordered by desc. The code does work. The next step is to search the query result to see is if a certain feild has a result. <?php

Include("config.php");
$con;
if (!$con)
  {
  die('Could not connect: ' . mysql_error());  }
$result = mysql_query("SELECT * FROM photos ORDER BY photo_id DESC LIMIT 1");
while($row = mysql_fetch_array($result))
{
echo $row['photo_id'];
}
?>

View Replies !
Query Doesn't Show First Result
I've created this query but it never shows the first result. I can have any number of results and order them however I like but whatever the first result in the list is it doesn't appear. Code:

View Replies !
Query Result Display
PHP Code:

<html>
<head><title>Display Table</title></head>
<body>
<?php
$database="temp"; /* DB name */
$host="localhost";
$user="root"; /* Set DB Username */
$pass=""; /* Set DB password*/
mysql_pconnect($host,$user,$pass); /* DB connect....*/

View Replies !
Field Name Of Result Query
I want to get name of the fields of a result query i.e. i have a query

$result=mysql_query("select * from reports order by report_id desc");

One thing is clear here i don't know how many fields present here above query is a example bcoz actul is a too much long query that's why i am using a simple query. i can get value easily like this

while($row=mysql_fetch_array($reslult))
{
$abc=$row[0];
}

View Replies !
Limit Query Result According To A Criteria
I have the following code which doesn't work:

"SELECT COUNT(*) AS total FROM $table_name
WHERE certain criteria HAVING total<=100";
The query above doesn't work and i get zero results.

In general the query take lots of time mainly because the criteria is not specific enougth and I get many many hits. I want to stop the query after getting the first 100 hits according to a certain criteria. When I use LIMIT 0,100 and not HAVING i get result from the first 100 records in the table but my table contain few million records.

View Replies !
Query Result Navigator Function
I've just updated this, and I thought I'd also say that not only can this provide a page navigation for MySQL or other database results, but can be used to navigate other lists.. such as a file list. PHP Code:

View Replies !
Easiest Way To Print The Result Of A Query
I am using the following code:

$host ="";
$username="";
$password="";
$database="123";
mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT SUM(rcountry) FROM 123 WHERE sessid = '$PHPSESSID'";
$result=mysql_query($query);
$num=mysql_num_rows($result);
mysql_close();

Whats the easiest way to print the results of the query? I just need the value returned by this section: $query="SELECT SUM(rcountry) FROM 123 WHERE sessid = '$PHPSESSID'";
I will be using the value in a mathmatical problem later on, but for now I just want to print it out and I am unsure as to which variable to echo.

View Replies !
Variable Interpolation From Sql Query Result
I have data in a MySQL table like:
the variable is: $var

and an assignment in a file like:
$var = "some text";

but when I print the output of a query for the data it prints:
the variable is: $var

rather than:
the variable is: some text

View Replies !
Multiple Result Sets With One Query
I need to query the DB and find records that coorespond to a given month and then display the data.

$sql="select * from $tbl where month='january'";
....... through december

My question is this -> is it better to create 12 different queries or create one query and use an array (or somethiing else) to create basically 12 result sets? To me - 12 queries seems like it would be taxing on the db.

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved