If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > PHP > mysql_fetch_array() problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-20-11, 22:43
gilgalbiblewhee gilgalbiblewhee is offline
Registered User
 
Join Date: Jul 2004
Posts: 494
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:
Quote:
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
Reply With Quote
  #2 (permalink)  
Old 04-21-11, 03:44
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
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 my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 04-21-11, 12:37
gilgalbiblewhee gilgalbiblewhee is offline
Registered User
 
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
Reply With Quote
  #4 (permalink)  
Old 04-21-11, 13:12
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
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 my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #5 (permalink)  
Old 04-21-11, 13:39
gilgalbiblewhee gilgalbiblewhee is offline
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On