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.





Same Mysql Query Doesn't Always Return A Result


We have no access to a mysql NG on my provider's server, so we ask here:

We have a long query (long in text) with a UNION between 2 select.

We have been informed that some times the query doesn't return any result.
We have tried on our server and we always get a result. BUT, trying on the
hosting server, many times the query doesn't return any result and doesn't
get any error.

Any idea ? does Union have any problem ? how to check if the query failed ?
My hoster said that sometimes the table can be locked (if the server is
overloaded) and then mysql doesn't return any result, but this seems to me
an aberration.

the query takes about 0.0050 sec to execute when it doesn't return any
result, and 0.030 when I get results




View Complete Forum Thread with Replies

Related Forum Messages:
Mysql Doesnt Return All Results Of A Query
I have an sql query like this:
SELECT column FROM table WHERE column1="3" AND column2="1"
This query works perfectly if i run it in the command line, to be
exactly it return two results.
But if i run it from php i just get the first of the two results.
Any ideas?

Mysql 4.1.8
php 5.0.3

I have a second problem. But its more of a question.
if i run the foreach loop on an array like this
array("id" => "78"), then it splits 78 up in 7 and 8.
Now you say its stupid to use a foreach for this array. But in the
function there i use it the array could also be two dimensional.
Is this behavior normal? I looked in the php manual but found nothing.

View Replies !
Select Query - Count Does Not Return Correct Result
I have "enrollment" table with the following structure:

CREATE TABLE `enrollment` (
`enrollmentID` bigint(20) NOT NULL auto_increment,
`coursename` varchar(200) NOT NULL default '',
`studentID` int(4) NOT NULL default Ɔ',
`semestername` varchar(100) NOT NULL default '',
PRIMARY KEY (`enrollmentID`)
)

This table is populated with coursenames that students have enrolled in a particular semester. Given a semestername and coursename, my Select query is trying to retrieve all the coursenames and count of the number of students enrolled in each of the courses for the given semester (except for the given course). Code:

View Replies !
How Do I Return Result Of Mysql Row Deletion
The data entered by a user on form 1 on page1.php is posted to
delete.php to remove that row from a table. After the SQL operation
the user is returned to page1.php.

How can I determine the success or failure of the SQL operation so I
can display an appropriate response message to the user?

View Replies !
Mysql_free_result Return Error Saying Not Valid Mysql Result Resource
im trying to do a query which takes rows of large amounts of text data
and displays them one after another. the size of the fields is causing
the page to be massive in size. so to try and reduce this im trying to
use mysql_free_result to clear the contents from memory.

however its returning an error saying not valid mysql data when im
certain that it is.

is this because im using a while loop like this...?

($row = mysql_fetch_result($result)) {
mysql_free_result($result);
}

View Replies !
Odbc_fetch_array Doesnt Return Any Values
My problem is odbc_fetch_array returns no value at all, but the scripts returns no error and all i can see in the page is the html table without any data in it..

the connection to oracle via odbc works, and in my other scripts i used odbc_fetch_row to retrieve data, but this one is kinda slow in getting massive amount of data from oracle. im now testing which is faster, odbc_fetch_row or odbc_fetch_array? but odbc_fetch_array returns no value at all. PHP Code:

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 !
MySQL Query Return Category Name Instead Of #
I Have 2 MySQL tables of interest here. 

Table 1: categories
ID
name

Table 2: items
ID
category (this relates to the category ID in Table 1)
title

I want my table on my webpage to show the category name from Table 1 instead of the category number in table 2. Code:

View Replies !
MySQL Query Result Rows
Still learning the ropes of PHP/MySQL here so pardon if this is something from a 101 class. I am wanting to know if/how I can query a MySQL database, pull two rows of information and assign them individual variable names. I know this isn't too clear. Let me try to explain what I want to do. Let's say I have something similar to this:
Code:

$query = mysql_fetch_assoc(mysql_query("SELECT entry_id, user_id, date FROM my_entries WHERE user_id = '$user_info[user_id]' ORDER BY date DESC LIMIT 2"));


What I would like to be able to do is assign separate variables for the info on the two rows returned by the query. I want to have the following variables:

$first_date = $query[date]; <= from the first row
$second_date = $query[date]; <= from the second row

I can then use the two variables to compare to each other, etc. Can this be done with a single query? Or are two queries required (if so how)?

View Replies !
Processing MySQL Query Result
after executing the query, say it returns 1000 results. if i just want to do some sampling and like to have a look on 4 of them, how can i refer to these 4 random records out of 1000? i'm working on processing the result of $res_array which has 1000 records.

query = select * from test;

result = mysql_query(query);

records1000 = db_result_to_array($result);

//how to select/remove records1000 to get say, records4?


function db_result_to_array($result) {
$res_array = array();
for ($count=0; $row = $result->fetch_assoc(); $count++) {
$res_array[$count] = $row;
}
return $res_array;
}

View Replies !
Query Mysql, Return Highest Value Then Create Value +1
I have a product input form I created (with php freaks help) for my website which I input general information and specs on our products. What I'd like to do now is when that form loads, it searches a seperate table and looks for the highest "ID" number.

It returns the number, adds 1 to it and displays the number somewhere on the input form for reference + error checking. When the form is submitted it takes that form and creates a record pushing that number in the correct field.

View Replies !
MySQL Query Over 3 Tables And Return Results
I am having trouble coming up with a query for the database I designed. In its simplest form I have three tables:

Characters table | character data
voiceactors table | voice actor data
char_voice table | character ID and corresponding voiceactor ID

My problem is that seperately I can query all of the character information, then query again to get the corresponding voice actors for the character(there is often more than one) However, I can't figure out how to select the character information and the voice actors for that character in one query. Code:

View Replies !
How Can I Populate A Listbox With The Result Of Mysql Query?
I would like to populate a listbox with the result of a mySQL Query.

View Replies !
How To Get Mysql Query Result Into Temp. Txt File
I did a lite search in the archive but didn't find anything specific to my problem. Here is what I am trying to do:

I've got a table with about 25k entries of company addresses. I need to be able to pull specific data out of the table and put it in a temporary text file and then display the result in the browser for the user to save locally.

The query part and the format of the data is all simple enough but I am having trouble figuring out how to get the data from the query into a temporary text file and then displaying that file. here is what I whipped up but it obviously doesn't work: Code:
<?
$tmpfname = tempnam("/path/to/file/", "FOO");
$list = mysql_query("select * from FH_LIST where State='AK'");
while ($list_results = mysql_fetch_array($list)) {
$data = blah blah blah;
fwrite($tmpfname, ".$data
");
}

fopen($tmpfname, "r");
fpassthru($tmpfname);
?>

I get an error message saying:
Warning: Supplied argument is not a valid File-Handle resource (referring to $data).

View Replies !
If Result Of Mysql Query Is Only One Row/column, Why Use An Array?
If I'm doing a very specific select statement, which I know will only ever return one value, can I get that resulting bit of data without storing it in an array or object?
If not, is mysql_fetch_array() the fastest method for getting this one value?

View Replies !
MySQL Result Is Empty, But The Query Is Correct
I have written a script that grabs info from a database, and outputs it to a form. I figured I'd tidy things up a bit, and use a function to handle the queries, where I had previously hardcoded almost the same query several times. Code:

View Replies !
Selecting A Random Row Of A Mysql Query Result?
Let say I have a mysql query, which might yield more than 1 row when queried. How can I set up the query, so that it RANDOMLY selects one of the results? I know that I can do a LIMIT 1 command, but this will always yield the first row.

View Replies !
Grouping Mysql Query Result By Dates
I have a mysql query result that displays a set of news heading thats are sorted by the date that it was created. I was wondering how to group them so it produces the following layout. Code:

View Replies !
Can I Put A Mysql Query Result Directly Into A Multidimensional Array?
I have two joined tables:

Departments - which contains the department description and a key
Positions - which contains position data

What I'm attempting to achieve is to display the department title in one table cell and then list all the positions associated with that department in the cell under neither the title. I need to generate a table two column table with as many rows as required, depending on the number of departments, which is dynamic.

Do this I'm trying to turn the result of my SQL query into multidimensional array e.g. dept = VioP positions = "designer", "engineer" etc, which I can do then use to generate the table.

I've done a search on the forum and looked around the manual and I'm stumped on how to achieve this, a point in the right direction would be greatly appreciated. The query I'm using is below. PHP Code:

View Replies !
Send Mysql Query Result Displayed In A Table
I have just created a shopping cart and I would like to send my user the receipt of there order by email. The receipt is generated by a mysql query and is displayed within a table. I have worked out how to send a html using simple HTML code as my “$messageâ€&#65533; variable: $success = mail($to, $subject, $message, $headers);

But I can not get it to send my mysql query result displayed in a table. How can i create the result of my mysql query and make it a simple variable i.e $message.

View Replies !
MySQL Query - Return Where A Particular Player Is In That List Ordered By High Score.
I have a table that holds players scores for a game im trying to make, what i want to do is return where a particular player is in that list ordered by high score.

I know that i could work this out with PHP - but i think that i would need to return the whole player scores table which given there could be a couple of thousand players of this thing (ever the optimist) seems rather drastic given that i just want one tiny number. Code:

View Replies !
Return 30 Or The Amount Of Actual Rows The Query Would Return If It Wernt For The LIMIT.
i have a query such as:

SELECT * FROM cars WHERE carmake='FORD' LIMIT 0,30

if i run a mysql_num_rows on this, will it return 30 or the amount of actual rows the query would return if it wernt for the LIMIT.

View Replies !
Return Result Set In SPs
how can we have a select satement in an SP?(i want to return a result set from the SP). i want to migrate from SQL Server to MySQL and i don't know what to do with these SPs.
it can be done in MySQL client, but it gives the error:"procedure foo can't return a result set in the given context MySQL" in the application. can i set a cursor out put parameter and return it?(just like Oracle) or it has another solution?

and another question: is MyODBC 3.51 tested with MySQL 5.x? can we call an SP from Delphi via MyODBC? (i tried to do so (using ADO an a data provider for OLEDB) but i think somewhere in passing the call statement it had put {} around "call sp()" statement so that mysql returned an error about the syntax.) .

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 !
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 !
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 !
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 !
Bad SQL Query Return
Basically, I'm looking to set two different types of SESSION variables depending on if the user should have extra permissions or not.

However, I'm having issues getting it set up correctly. I've tried a number of different things, but just cant seem to figure out what exactly is going on. The code that is having problems looks like this. 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 In PHP Won't Return Results In There's Only 1
$sql = 'SELECT `PageTitle` '
$sql .= 'FROM `Pages` '
$sql .= 'WHERE `PageID` = 1 LIMIT 0, 30'

I have run this query in MySQL control panel and it works perfectly.
When I try to do it via PHP I get no results.

If I select all rows (i.e I don't specify a "WHERE") I get one fewer
rows returned than there actually are.

View Replies !
Return Query Pagination
The attached code is suppose to query a database and return records between two dates and update the pagination links. It works at first, but as soon as I click on a pagination link it re-queries the database and returns all of the records. Code:

View Replies !
Return Bool From Query
I have a mySQL system with a news publishing part in it. Admins can create new items with text in it, and they have an option to create 'fulltexts', so you'd get "read more ..." on the front page, click it and read the fulltext.

Is there a possibility for mySQL (query) to check if 'fulltext' is empty or not, and only return true or false, so i don't have to put the whole fulltext into the mysql_fetch_array() to decide wether or not to show 'read_more', or should i create an extra boolean field in the DB saying fulltext y/n ?

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 !
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 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 !
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 !

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