[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Warning: SQL cant jump to...

Posted on 2006-11-04
8
Medium Priority
?
238 Views
Last Modified: 2006-11-18
is this warning a big deal?

ive been writting a few things where i have it jump directly to row 0...

is that bad?

example: $ownerscreenname = mysql_result($sql_blogcommentsn,0,"users.username");


better approach?
0
Comment
Question by:n8dog
  • 4
  • 4
8 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1000 total points
ID: 17874094
usually, msql_result is not recommended, as it is slower than the other methods...

so, what are you trying to do in general?

usually, you loop with mysql_fetch_assoc() on the resultset, and have hence the results in a nice array:
http://php.net/manual/function.mysql-fetch-assoc.php

if ($sql_blogcommentsn = mysql_query($sql))
{
   while ( $row = mysql_fetch_assoc($sql_blogcommentsn))
   {
       $ownerscreenname = $row["username"];
   }
}

note that you don't specify the table name of the column when you access the field. if you have the same fieldname when joining multiple tables, you have to give them alias names in the query so they can be distiguished later...
0
 

Author Comment

by:n8dog
ID: 17874104

jeez, i use that manner of accessing all of my database stuff... and the site im working on its 100% db based..

woops!


what level of speed difference are we talking about here?
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17874131
well, I never tried it, as I avoided that function from the beginning on...
the gains should be subsecond usually, so only be important when the page would suffer from heavy traffic.
now, mysql_result can of course be used, for example when you have queries like "select count(*) from ... " where indeed you only need to fetch a single row/column.

to come back to the actual "warning". it should not be ignored, because probably it means you have an issue.
it could be that the query returned no rows at all, or you are trying to run the function several times at once in 1 line of code ,
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:n8dog
ID: 17874338

well for instance when im looking up a particular record, just indentify it directly, knowing that i will only get 1 row back..

so then i use $ownerscreenname = mysql_result($sql_blogcommentsn, 0 ,"users.username");  // NOTE: the 0 in place $counter
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17874352
if ($sql_blogcommentsn = mysql_query($sql))
{
   if ( $row = mysql_fetch_assoc($sql_blogcommentsn))
   {
       $ownerscreenname = $row["username"];
   }
}

now again:
* dont use the table name when getting the field value!
* are you sure that there is 1 row all the time?
0
 

Author Comment

by:n8dog
ID: 17874510


well, i should probably upgrade my method of working with it then, yes?

my errorlogs are filled with TONS of warnings regarding this.. with my users using the blogs, forums, etc.. they get hit pretty often. thus creating this..

although i guess i could turn off warnings too...

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17875683
>although i guess i could turn off warnings too...
that's of course the lazy method... just hiding all the potential other issues...
0
 

Author Comment

by:n8dog
ID: 17875695
you're 100% correct.. i wanted to feel lazy for a moment.. ok, the moment is over :)

-n

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month19 days, 5 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question