Solved

Warning: SQL cant jump to...

Posted on 2006-11-04
8
194 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 142

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 142

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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 142

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 142

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses four methods for overlaying images in a container on a web page
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…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now