Solved

Warning: SQL cant jump to...

Posted on 2006-11-04
8
220 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

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…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

728 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