Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2004
    Posts
    494

    Unanswered: mysql_fetch_array() problem

    This gives a plank page:
    PHP Code:
    <?php
    include("../includefiles/dbconnection.php");
    $bk=isset($_GET["book".$no]) ? $_GET["book".$no] : "";
    $ch=isset($_GET["chapter".$no]) ? $_GET["chapter".$no] : "";
    $vs=isset($_GET["verse".$no]) ? $_GET["verse".$no] : "";
    $source=isset($_GET["source".$no]) ? $_GET["source".$no] : "";
    $sourceAbb=Array("kjv""mt""mtnv""tr");
    $SourceName=Array("King James""Masoretic Text""Masoretic No Vowels""Textus Receptus");
    $SourceTable=Array($dbTable3$dbTable7$dbTable9$dbTable8);
    for(
    $i=0$i<count($SourceTable); $i++){
        if(
    $source==$sourceAbb[$i]){
            
    $sql "SELECT * FROM ".$SourceTable[$i]." WHERE book = '".$bk."' AND chapter= '".$ch."'";
            if(
    $vs != 'all'){
                
    $sql .= " AND verse= '".$vs."'";
            }
            
    $sql .= " ORDER BY id ASC";
            
    //echo $sql;
        
    }
    }
    if(
    $result){
        
    $result mysql_query($query);
        while(
    $row mysql_fetch_array($result)){
            
    $id[] = $row['id'];
            
    $bookTitle[] = $row['book_title'];
            
    $book[] = $row['book'];
            
    $bookAbb[] = $row['book_abb'];
            
    $chapter[] = $row['chapter'];
            
    $verse[] = $row['verse'];
            
    $textData[] = $row['text_data'];
        }
    ?>
    <div style="float: left; margin: 5px 0px 0px 0px; background-color: #7A1010; width: 183px; height: 19px; border: 1px solid #7A1010; color: white; font-weight: bold; text-align: left; padding: 0px 0px 0px 5px;">
        <span style="float: left; padding: 2px 10px 0px 2px; color: #FFFFFF; font-family: arial; font-weight:bold; font-size: 13px"><input id="chk_all" name="checkallresults" type="checkbox" style="float: left;" onClick="if(this.checked == true){for (i=0; i<document.getElementsByName('checkresult_<?php echo $no?>').length; i++){document.getElementsByName('checkresult_<?php echo $no?>')[i].checked = true ;
    }}else{for (i=0;i<document.getElementsByName('checkresult_<?php echo $no?>').length; i++){document.getElementsByName('checkresult_<?php echo $no?>')[i].checked = false;}}" />all</span>
        <span style="float: left; height: 10px; padding: 2px 10px 0px 2px; color: #FFFFFF; font-family: arial; font-weight: bold; font-size: 13px"><?php echo $bookTitle[0]. " " .$chapter[0];?></span>
    </div>
    <div id="txt_<?php echo $book[0]."_".$chapter[0]."_".$no?>" style="float: left; background-color: #EAE8C8; margin: 0px 0px 0px 0px; width: 178px; height: 407px; border: 1px solid #7A1010; padding: 5px 5px 0px 5px; overflow-y: auto; overflow-x: hidden;">
    <?php 
        
    for($tdid=0$tdid count($id); $tdid++){
            echo 
    "\t\t\t\t\t<p id=\"regular[]\" name=\"bibletext\" style=\"float: left; text-align: left; width: 155px; display: block; padding: 0px 2px 0px 2px; font-size: 12px;\"><input id=\"check".$no."_".$tdid."\" name=\"checkresult_".$no."\" type=\"checkbox\" onclick=\"\" value=\"".$id[$tdid]."\" /><span style=\"font-weight: bold; margin: 2px;\">"."[".$id[$tdid]."] - ".$verse[$tdid]."</span>";
            
    $strText stripslashes(mysql_real_escape_string($textData[$tdid]));
            include(
    "../includefiles/highlight_getText.php");
            echo 
    "</p>\n";
        }
        echo 
    "\t\t\t\t\t</div>\n";  
    }
    mysql_close($con);
    ?>
    But when I remove the if($result) then it would point out:
    Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in thewheelofgod\twotexts\getfiles\getTextinclude.php on line 22
    What's the solution?
    Compare bible texts (and other tools):
    TheWheelofGod

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Im not surprised that code geenrates no output
    first off what do you thinl the for loop is doing?
    next what do you think the if($result) statement is doing
    at waht point do you think you atually query the database?
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jul 2004
    Posts
    494
    Quote Originally Posted by healdem View Post
    Im not surprised that code geenrates no output
    first off what do you thinl the for loop is doing?
    next what do you think the if($result) statement is doing
    at waht point do you think you atually query the database?
    I forgot to change $query to $sql.
    Compare bible texts (and other tools):
    TheWheelofGod

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Quote Originally Posted by gilgalbiblewhee View Post
    I forgot to change $query to $sql.
    no problem, no ones perfect, no one that I know never ever makes mistakes unless they don't try anything, are aliens or just plain liars.

    but what have you learned from this?
    have you developed any debugging strategies
    Google

    as it happenms I reckon the mistake was pretty trivial, and pretty trivial to find. to succedd as a PHP developer you need develop your own line of debugging strategies
    you need to understand what to look for
    youneed to work out how to eliminate errors. bear in mind its not just compile errors its alos logic errors.

    the or die contruct is usefull
    stuffing values into a debug variable and then showing that helps.
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Jul 2004
    Posts
    494
    Quote Originally Posted by healdem View Post
    no problem, no ones perfect, no one that I know never ever makes mistakes unless they don't try anything, are aliens or just plain liars.

    but what have you learned from this?
    have you developed any debugging strategies
    Google

    as it happenms I reckon the mistake was pretty trivial, and pretty trivial to find. to succedd as a PHP developer you need develop your own line of debugging strategies
    you need to understand what to look for
    youneed to work out how to eliminate errors. bear in mind its not just compile errors its alos logic errors.

    the or die contruct is usefull
    stuffing values into a debug variable and then showing that helps.
    Yes you're right. Some of my codes though are very old and I haven't incorporated all the new things I've learned into it yet. I have so many files that it's hard for me to change all at once.
    Compare bible texts (and other tools):
    TheWheelofGod

Posting Permissions

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