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




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 Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
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:

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:

Add Include Or Echo To A Query
I would like to add an include, or an echo to a query. I have several different files that are selecting from the same table.  When I make a new table I have to manually change the table name in each file. I would like to be able to do it once and it will be read by each file.

I have tried this
$query = "SELECT email_address as email FROM include ['table.php']";
I am getting a syntax error on the include ['table.php'].

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

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

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.

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:

Echo Wont Work On Second Query
I have two queries searching for UserID on two tables... but it wont echo my second query.. the first one works how ever even though they are structured the same. This is what i have: Code:

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.

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:

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.

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

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.

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

Moving A Query Result Into An Array
I have read all the array stuff done searches for examples, but am still not clear if there is a way to do a query from a MySQL table and move those vaules into an arry.

I am sure it can be done, but I thought I would find a function that would do it. Am I just overlooking something?

$resultID = mysql_query("SELECT DISTINCT slot FROM items");
while(list ($slot) = mysql_fetch_row($resultID)){echo"$slot";}

So anyone have a good way to move the result into some array?

Obtain Parameter From Result Query
In PERL: $trx_status = lc(param('eTrnStatus')); How to do equivalent in php?

Sending Query Result To Excel
How can I send query result to EXCEL in PHP pages? is there such a function in PHP ? any code example !

Strange Result From Table Query
I have a simple query that I am restricting to the first 4 character, however instead of the first 4 characters I am getting only the characters from the end of the field.

The information in the field resembles: 4285-002

My result should be: 4285

What I am getting is: -002

The following is the code to pull the dat from field 'Dest':
    $dest=odbc_result($rs1, 'Destination');
        $deststrcount=1;
        $deststr = $dest;
        $deststr = str_split($deststr,4);
        foreach($deststr as $destv){
          if ($deststrcount<="1"){
            $desttext=$destv;
            $destnew = "DEST[1,$deststrcount] $desttext";
 
            $strcount=$strcount+1;
            }

Query Giving Array As Result
I just started PHP and getting the following error when trying to read and echo something from my DB. I get Array as an result of a working SQL query (I tested it in PHPMyAdmin SQL Query) and it should be something else. Array doesnt return in the database i selected, but still it's here.

<?
$host="localhost";
$user="xxxxxxxxx";
$password="xxxxxxxxxxx";
$dbname="mohaaleague";
$connection = mysql_connect($host, $user, $password) or die ("Kan niet verbinden");
$clan = "Belgian Fun Clan";
$db = mysql_select_db ($dbname,$connection) or die("Je Stinkt");
//SELECT clan FROM clan WHERE clan='Belgian Fun Clan'
$query = "SELECT clan FROM clan" or die("Query Mislukt");
$result = mysql_query($query) or die("Query Mislukt1");
$row = mysql_fetch_array($result, MYSQL_ASSOC) or die("Query Mislukt2");
extract($row);

echo($row. "<br>");
if ( $clan == $row )
{
echo "het werkt";
}
else
{
echo "het werkt niet";
}
$disconnect = "mysql_close";
?>

Echo Multiple Row's From Mysql Query
Im not sure if im using the right logic her but Im trying to output multiple rows of data which = techid in the data table. The mysql data table consits of the following columns:

CALL_ID  ID  FirstName  EMail  LastName  cat_id  descrip  status  priority  phoneNumber  phoneExt  mobile  ticketVisi  pageView  TechID  cost  Time_Logged 

I have a function which is displaying ques Code:

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.

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).

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?

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:

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.

Result Query - Producing Extra Results?
what am i doing wrong here?

$startrow=0;
$limit=20;

$qry = mysql_query("SELECT bodycare.*, haircare.* FROM bodycare, haircare WHERE bodycare.avail='true' AND haircare.avail='true' LIMIT $startrow, $limit")or
die(mysql_error());

it should return 6 results between bodycare and haircare. instead it returns 8, - 4 repeats of the first haircare product and 4 of the second haircare product. There are only 2 haircare products in total and 4 bodycare, but the bodycare aren't turning up at all

why? can you help me fix it?

Pulling Only 3 Digits From A Query Result Issues
I'm been playing with this for a few days and I can't seem to come close to getting this to work. Here is the situation. End users use their zip code to search for businesses. Well I want the search to show more then just what is in their zip code but really in their area.

Easiest way I have found to do this is displaying all businesses that start with the same 3 digitals as their zip code. Example: there are businesses in Joplin, MO (64801) and in Neosho, MO (64850). When someone types in 64801 (Joplin) I want it to show the businesses in Neosho (64850) also.

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:

$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.

Echo: How To View/call Data From Separate File Into Echo
I would like to ask about echo "<--statement==>";

Ok my senario let say like this i got a file name as datax01.php & script.php

Let say on script.php i got a code to use echo. So how from echo i can recall datax01.php to view on that script? Code:

Is There A Way To Echo An Echo Command?
Is this possible ? for those of you who don't understand what am i trying to ask:

<?php echo '<?php echo "This is what i'm trying to do!"; ?>'; ?>

Displaying Result 1-8, Then Result 9-17 Etc.
I dispaly the results from the database like this.

<? while ($row = mysql_fetch_array($prod_result)) {
$small = $row[0];
echo"<td align=center><img src="produkter/hardware/decks/$small"></strong></td>";}?>

But if there are more than 8 results, I wnat to dispaly the first 8 on one page, then the next 8 on the next page...How can this be done?

Nesting Result Loops Within Result Loops Possible?
I'm looping through a query, and inside the while result output, I am trying to loop through a second query (created from the 1st query's row results).

I have checked that both queries return info.

I can see that the 1st while result output works fine, but when I get to the inner while result output, it never returns any rows (nothing in the while loop evaluates).

So, IS it possible to nest one query's output loop within another, or am I doing something wrong?

REGEX: Can't Seem To Replace LIMIT Clause In Query Using Preg_replace ($pattern, $replacement, $query)
Want to replace the limit clause in a query, but can't get it right.
What's wrong with this:

$pattern = "(.*)limit (.*)";
$replacement = '$1'
$replacement .= "LIMIT $limit";
$replacement .= '$2'
$query = preg_replace ($pattern, $replacement, $query);

PHP Update Query Mysql: Query Succussful?
I can't seem to successfully test an update query. Below is a piece of code that updates a statistics table. If row today doesn;t exist, a new day must be created. But this doesn't work...

thank you for your reply.

$today= date("Y-m-d");

$qq="update totals_r set hits_r=(hits_r+1), lang_$lang=(lang_$lang+1), cat_$cat=(cat_$cat+1), rating_$rating=(rating_$rating+1), bussite_$bussite=(bussite_$bussite+1) where date='$today'";

$result_6 = mysql_query ("$qq");

if (!$result_6){ /// IF !ROW_TODAY ==> CREATE NEW DAY

$qq_2="insert into totals_r (hits_r, lang_$lang, cat_$cat, rating_$rating, bussite_$bussite, date) values(&#391;',&#391;',&#391;',&#391;',&#391;','$today')";

$result_6_2 = mysql_query ("$qq_2");

if (!$result_6_2){
$err_msg_sql_6= mysql_error();
$err_loc_6="$PHP_SELF"." // Query6: update totals_r";
}
}

Empty Query, Query Fail
i am doing a user authentication but my problem is that when i type in user name and password it is Code:

To Echo Or Not To Echo
Which is faster for the server to process:

HTML inside echo tags or outside of PHP altogether?

Echo To Php
I know it may seem odd, but is it possible to echo to php? I mean
neasting php within php?

example

<?php
$array_levels="[1][2][3]";
$my_array<?php echo $array_levels; ?>="hello world"
?>

It may seem stupid but would be powerful, wouldn't it?
How can I accomplish what I just did differently?

Echo Or Not To Echo?
I have a couple pages that have tables, whats best use echo to produce the
full table with the variables or is it best to just make the table in plain
html and use <?php echo ('$va'l); ?> when i need to see some value.

Example, I have tables like this:

Help With Echo
Hi,

Im trying to get a form to display using php

I have sonme code eg.

conditional code
if true then
echo ('<form
target="paypal"action="https://www.paypal.com/cgi-bin/webscr"
method="post">');
etc
etc

When I runn it I get Parse error: parse error, unexpected T_STRING in
C:Program FilesApache GroupApache2htdocsPagesmrwhois_sample.php on
line 24

Line 24 being the echo line

Echo
what is the diference between doing: echo 'something' or echo "something";

PHP In Echo
Is it possible to put PHP in an echo? If so, how would I?

Echo
I am either too tire to think or not seeing it.  I have a echo statement as follows:

echo "Flight request date: " . "$date = $flight['Dept Date']";  does not display as suppose to. I am missing something?

PHP In Echo
Is it possible to put PHP in a echo statement, so that i could, say have something like this:
echo('Hello you are visiting this page: <?php echo(PHP_SELF) ?>');

Or whatever?

Echo Within Echo
Essentially, I want to incorporate some captcha code that I have working elsewhere in a simple form element into some more complex php code.

Basically, I currently have:

content .='blah blah';
content .='blah blah';

echo $content
However, my captcha code is as follows:

<img src='captcha.php?f=<?php echo $f;?>'>
$f is declared earlier with the relevant randomisation code.

However, if i combine the above into:

content .='blah blah';
content .='blah blah';
content .='<img src='captcha.php?f=<?php echo $f;?>'>';

echo $content
The captcha image displays but it is always the same image - it does not randomise.

Echo...
I'm trying to create a php 404 file however I dont know the command to echo the file you are trying to access I tried Quote<?php echo $_SERVER['PHP_SELF']; ?> but that just echoed 404.php

Echo Before Value?
I was wondering if there's anyone to do the echo before saying what the echo of the value is.

<?php  echo $header; ?>
<?php $header= "test"; ?> 

Displays nothing, while doing that backward of course does since it reads the page top to bottom.

I'm splitting the pages into header and footer and want to header (title of the current page) to be like this so i can just start my pages off saying what the page is with the header= "blah blah blah"

Echo A URL
i want to run and if statement and if something is true then redirect the user to another page.

SQL Last Result
When querying and doing a loop I want to specify that the last result of the loop does not include a horizontal line. How would I do this?


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