CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Help! Php sql

  1. #1
    Join Date
    Dec 2008
    Posts
    27

    Help! Php sql

    im using PHP MySQL

    i have this code

    PHP Code:

    <?    $query1 = mysql_query("SELECT so_trouble_reported.tr, trouble_reported.code as trcode
                                    FROM so_trouble_reported
                                    JOIN trouble_reported ON so_trouble_reported.tr_id = trouble_reported.tr_id
                                    WHERE so_trouble_reported.so_no = $so_no"); 
                                    
            $query2 = mysql_query("SELECT so_findings.findings, findings.code as fcode
                                    FROM so_findings
                                    JOIN findings ON so_findings.findings_id = findings.findings_id
                                    WHERE so_findings.so_no = $so_no"); 
                                    
            $query3 = mysql_query("SELECT so_service_performed.sp, service_performed.code as spcode
                                    FROM so_service_performed
                                    JOIN service_performed ON so_service_performed.sp_id = service_performed.svc_per_id
                                    WHERE so_service_performed.so_no = $so_no");                     
                    
                    for($ctr=0;$ctr<=3;$ctr++)
                    {                
                                    ?>   
              <tr>
                <td align="center" class="txtformat1"><? echo mysql_result($query1,$ctr,'trcode')?>; <? echo mysql_result($query1,$ctr,'tr')?></td>
                <td align="center" class="txtformat1"><? echo mysql_result($query2,$ctr,'fcode')?>; <? echo mysql_result($query2,$ctr,'findings')?> </td>
                <td align="center" class="txtformat1"><? echo mysql_result($query3,$ctr,'spcode')?>; <? echo mysql_result($query3,$ctr,'sp')?></td>
              </tr><? } ?>

    as u can see i have 3 queries and print its value using a mysql_result function.

    i made a $ctr to print it until 4 values. if theres is a value fetched from the $query the printing is OK. but if the $query dont get values. the printing says:

    Warning: mysql_result() [function.mysql-result]: Unable to jump to row 1 on MySQL result index 5 in C:\xampp\htdocs\SOMS\view_service_order.php on line 261


    now what i want to do is when the $query dont retrieved any values it will print a "SPACE"

    i want to put a condition were if no values retrieved it will change variables to "SPACE"
    else if values retrieved print values.


    HELP!

  2. #2
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,943

    Re: Help! Php sql

    First off, you shouldn't be directly echoing the mysql_result. Instead, within the for loop, set a variable for each of the 6 outputs. Then, you can use empty() to check for a value. If there is not, just print an empty space.

    You can also do a similar thing with the return from the queries. Check to see if they pass. If the execution passed, then go on to the for loop.

    PHP Code:
    if ($query1 && $query2 && $query3) {
      for... 
    Note: You probably should be using <?php instead of just <?. There have been many people who have encountered functionality failure when truncating it.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Aug 2002
    Posts
    879

    Re: Help! Php sql

    To that what PeejAvery mentioned already,
    it seems to me that there is a lack of basic php/sql knowledge,
    there are better ways to reach what you want.

    Is there a special reason why you put the whole stuff
    in a for loop?

    Did you checked out
    http://de2.php.net/manual/en/function.mysql-result.php
    the first entry describes your problem exactly.

  4. #4
    Join Date
    Dec 2008
    Posts
    27

    Re: Help! Php sql

    i try to use brute force here and it works perfect.

    i get it query by query.

    anyway, still

    tnx guys!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)