Re: [PHP-DB] Re: PHP and MySQL queries...
Ok I made the changes and now I am getting these 2 errors... Warning: 0 is not a MySQL result index in search01.php on line 141 and this one... Warning: 0 is not a MySQL result index in search01.php on line 143 No rows found On line 141 - $count = mysql_num_rows($results); On line 143 - if (mysql_num_rows($results) ) I am not sure what this error message means, does that mean that there were no results to display? Oh by the way I sincerely want to thank you for helping me out with this, I have been working on it for a few days and just today decided I should get help with it. Thanks again. Jason "Rick Emery" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > OK. Ya followed me just a little too literally. We needed you to > restructure. So you're part way there. > i've made some changes below. > > I don't have access to PHP here at work, otherwise I'd test the changes I > made below. So you'll have to test them. > > You'll note that I placed the while(){} loop where it should be. > I also split the Name line into two different array elements. The array > element names refer directly to the variables after SELECT in your SELECT > query. > I did the same in the Phone line. > > -Original Message- > From: Jason Gerfen [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, October 23, 2001 2:23 PM > To: [EMAIL PROTECTED] > Subject: RE: [PHP-DB] Re: PHP and MySQL queries... > > > Ok here is what I have done after your suggestions... > if ($date == "") > {$date = '%';} > > $result = mysql_query ("SELECT > fname,lname,address,city,state,zip,phonea,phone,email,crty,crnum,crmo,cryr,w > eeks,ogden,rock,logan,ipaddress,ad,total,num,date,time > FROM ads WHERE date LIKE > '%$date%' LIMIT 0, 30 "); > $count = mysql_num_rows($results); > > if (mysql_num_rows($results) ) > { > while( $row = mysql_fetch_array($result) ) > { > >print "Name: ".$row['fname'].", ".$row[' lname']."\n"; >print "Address: ".$row['address']."\n"; >print "City: ".$row['city']."\n"; >print "State: ".$row['state']."\n"; >print "Zip: ".$row['zip']."\n"; >print "Phone: ".$row['phonea'].", ".$row[' phone']."\n"; >print "Email: ".$row['email']."\n"; >print "Credit Type: ".$row['crty']."\n"; >print "Credit Number: ".$row['crnum']."\n"; >print "Credit Date: ".$row['crmo']."\n"; >print "Weeks: ".$row['weeks']."\n"; >print "Ogden: ".$row['ogden']."\n"; >print "Logan: ".$row['logan']."\n"; > print "IP Address: ".$row['ipaddress']."\n"; >print "Ad: ".$row['ad']."\n"; >print "Total: ".$row['total']."\n"; >print "Ad Number: ".$row['num']."\n"; >print "Date: ".$row['date']."\n"; >print "Time: ".$row['time']."\n"; > } > } > else { > print "No rows found"; > } > ?> > After I have uploaded it to the webserver I now get a parse error on line > 201 and that is the end of the php file, so there isn't anything to change. > > I am still fairly new to this so any help you can provide would be great. > Thanks again. > Jason > > > >From: Rick Emery <[EMAIL PROTECTED]> > >To: 'Jason' <[EMAIL PROTECTED]>, [EMAIL PROTECTED] > >Subject: RE: [PHP-DB] Re: PHP and MySQL queries... > >Date: Tue, 23 Oct 2001 13:13:21 -0500 > > > >First o all, GET RID of the 19 constructs using mysql_result(). You've > >already captured the row with the $row=mysql_fetch_array(). > >mysql_result() cannot be mixed with mysql_fetch_arry(). > > > >So instead of: > >echo "Address: "; > >printf(mysql_result($result,$count,"address")); > >echo "\n"; > > > >use: > >print "Address: ".$row['address']."\n"; > > > >Next, dates are stored in MySQL as -MM-DD. Use that format in your > >input. > > > >Next, don't combine that "if(mysql_fetch_array())" with the "do while()" > >Instead, use: > > > >if (mysql_num_rows($results) ) > >
Re: [PHP-DB] Re: PHP and MySQL queries...
Let me guess, the parse error is on the last line of the file? I get that all the time, its usually caused by a loop thats still open... and, in your case, your "do" and "if" statements arent closed try this. mysql_connect ("db_hostname", "db_username", "db_password"); mysql_select_db ("db_name"); if ($date == "") {$date = '%';} $result = mysql_query ("SELECT fname,lname,address,city,state,zip,phonea,phone,email,crty,crnum,crmo,cryr,w eeks,ogden,rock,logan,ipaddress,ad,total,num,date,time FROM ads WHERE date LIKE '%$date%' LIMIT 0, 30 "); $count = -1; if ($row = mysql_fetch_array($result)) { $count ++; do { print "Name: ".$row['fname, lname']."\n"; if (mysql_num_rows($results) ) { while( $row = mysql_fetch_array($result) ) { } } else { print "No rows found"; } } } Let me know if it works!! -- Jason Wood Chief Technology Officer Expressive Tek, Inc. 407 Kehrs Mill Road Ballwin, MO 63011 Phone 636.256.1362 www.expressivetek.com "Jason" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > Ok here is the script after changes... > > mysql_connect ("db_hostname", "db_username", "db_password"); > > mysql_select_db ("db_name"); > > if ($date == "") > {$date = '%';} > > $result = mysql_query ("SELECT > fname,lname,address,city,state,zip,phonea,phone,email,crty,crnum,crmo,cryr,w > eeks,ogden,rock,logan,ipaddress,ad,total,num,date,time > FROM ads WHERE date LIKE '%$date%' LIMIT 0, 30 "); > $count = -1; > if ($row = mysql_fetch_array($result)) { > $count ++; > do { > print "Name: ".$row['fname, lname']."\n"; > > if (mysql_num_rows($results) ) > { > while( $row = mysql_fetch_array($result) ) > { > } > } > else { > print "No rows found"; > } > ?> > And now I get a parse error on line 201 which is below the html and php > code, so there isn't anything to change. Please help? > > "Rick Emery" <[EMAIL PROTECTED]> wrote in message > [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > > First o all, GET RID of the 19 constructs using mysql_result(). You've > > already captured the row with the $row=mysql_fetch_array(). > > mysql_result() cannot be mixed with mysql_fetch_arry(). > > > > So instead of: > > echo "Address: "; > > printf(mysql_result($result,$count,"address")); > > echo "\n"; > > > > use: > > print "Address: ".$row['address']."\n"; > > > > Next, dates are stored in MySQL as -MM-DD. Use that format in your > > input. > > > > Next, don't combine that "if(mysql_fetch_array())" with the "do while()" > > Instead, use: > > > > if (mysql_num_rows($results) ) > > { > > while( $row = mysql_fetch_array($result) ) > > { > > } > > } > > else { > > print "No rows found"; > > } > > > > Do the above. Re-submit. Tell me the results. W'ell go from there... > > > > rick > > > > -Original Message- > > From: Jason [mailto:[EMAIL PROTECTED]] > > Sent: Tuesday, October 23, 2001 12:37 PM > > To: [EMAIL PROTECTED] > > Subject: [PHP-DB] Re: PHP and MySQL queries... > > > > > > As of yet I have tried all sorts for date formating for the search field > to > > work. I.E. 2001-10-23, 10/23/2001, 10/%/2001, 10%, %10%, etc. The date > > field in the database is stored as 10/23/2001 and yet when a user enters > the > > date and clicks the search button it does not display the results. I am > > almost certain that as the user clicks the submit button the php script is > > parsing the search string (i.e. 10/23/2001) incorrectly. I believe it is > > parsing the sting as 10&nsb;23&nsb;2001 or something to that effect. If > > anyone has some more information on this please let me know. I am pretty > > sure I have exhausted my resources. > > > > "Jason" <[EMAIL PROTECTED]> wrote in message > > [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > > > I am having a hard time setting up a form for users to enter a date in > the > > > format of 00/00/ (of course they would use an actual date). My form > > is > > > as follows... > > > > > > *I.E. - Format is 04/01/2001* > > > Search for Ads by date: > > > > > > > > > > > > > > value="Submit"> > > > > value="Reset"> > > > > > > > > > > > > On my search.php page I have the following MySQL connection and search > > > parameters... > > > > > > > > mysql_connect ("db_hostname", "db_username", "db_password"); > > > > > > mysql_select_db ("db_name"); > > > > > > if ($date == "") > > > {$date = '%';} > > > > > > $result = mysql_query ("SELECT > > > > > > fname,lname,address,city,state,zip,phonea,phone,email,crty,crnum,crmo,cryr,w > > > eeks,ogden,rock,logan,ipaddress,ad,total,num,date,time > > > FROM ads WHERE date LIKE '%$date%' LIMIT 0, 30 "); > > > $count = -1; > > > if ($row = mysql_fet
RE: [PHP-DB] Re: PHP and MySQL queries...
OK. Ya followed me just a little too literally. We needed you to restructure. So you're part way there. i've made some changes below. I don't have access to PHP here at work, otherwise I'd test the changes I made below. So you'll have to test them. You'll note that I placed the while(){} loop where it should be. I also split the Name line into two different array elements. The array element names refer directly to the variables after SELECT in your SELECT query. I did the same in the Phone line. -Original Message- From: Jason Gerfen [mailto:[EMAIL PROTECTED]] Sent: Tuesday, October 23, 2001 2:23 PM To: [EMAIL PROTECTED] Subject: RE: [PHP-DB] Re: PHP and MySQL queries... Ok here is what I have done after your suggestions... if ($date == "") {$date = '%';} $result = mysql_query ("SELECT fname,lname,address,city,state,zip,phonea,phone,email,crty,crnum,crmo,cryr,w eeks,ogden,rock,logan,ipaddress,ad,total,num,date,time FROM ads WHERE date LIKE '%$date%' LIMIT 0, 30 "); $count = mysql_num_rows($results); if (mysql_num_rows($results) ) { while( $row = mysql_fetch_array($result) ) { print "Name: ".$row['fname'].", ".$row[' lname']."\n"; print "Address: ".$row['address']."\n"; print "City: ".$row['city']."\n"; print "State: ".$row['state']."\n"; print "Zip: ".$row['zip']."\n"; print "Phone: ".$row['phonea'].", ".$row[' phone']."\n"; print "Email: ".$row['email']."\n"; print "Credit Type: ".$row['crty']."\n"; print "Credit Number: ".$row['crnum']."\n"; print "Credit Date: ".$row['crmo']."\n"; print "Weeks: ".$row['weeks']."\n"; print "Ogden: ".$row['ogden']."\n"; print "Logan: ".$row['logan']."\n"; print "IP Address: ".$row['ipaddress']."\n"; print "Ad: ".$row['ad']."\n"; print "Total: ".$row['total']."\n"; print "Ad Number: ".$row['num']."\n"; print "Date: ".$row['date']."\n"; print "Time: ".$row['time']."\n"; } } else { print "No rows found"; } ?> After I have uploaded it to the webserver I now get a parse error on line 201 and that is the end of the php file, so there isn't anything to change. I am still fairly new to this so any help you can provide would be great. Thanks again. Jason >From: Rick Emery <[EMAIL PROTECTED]> >To: 'Jason' <[EMAIL PROTECTED]>, [EMAIL PROTECTED] >Subject: RE: [PHP-DB] Re: PHP and MySQL queries... >Date: Tue, 23 Oct 2001 13:13:21 -0500 > >First o all, GET RID of the 19 constructs using mysql_result(). You've >already captured the row with the $row=mysql_fetch_array(). >mysql_result() cannot be mixed with mysql_fetch_arry(). > >So instead of: >echo "Address: "; >printf(mysql_result($result,$count,"address")); >echo "\n"; > >use: >print "Address: ".$row['address']."\n"; > >Next, dates are stored in MySQL as -MM-DD. Use that format in your >input. > >Next, don't combine that "if(mysql_fetch_array())" with the "do while()" >Instead, use: > >if (mysql_num_rows($results) ) >{ > while( $row = mysql_fetch_array($result) ) > { > } >} >else { >print "No rows found"; >} > >Do the above. Re-submit. Tell me the results. W'ell go from there... > >rick > >-Original Message- >From: Jason [mailto:[EMAIL PROTECTED]] >Sent: Tuesday, October 23, 2001 12:37 PM >To: [EMAIL PROTECTED] >Subject: [PHP-DB] Re: PHP and MySQL queries... > > >As of yet I have tried all sorts for date formating for the search field to >work. I.E. 2001-10-23, 10/23/2001, 10/%/2001, 10%, %10%, etc. The date >field in the database is stored as 10/23/2001 and yet when a user enters >the >date and clicks the search button it does not display the results. I am >almost certain that as the user clicks the submit button the php script is >parsing the search string (i.e. 10/23/2001) incorrectly. I believe it is >parsing the sting as 10&nsb;23&nsb;2001 or something to that effect. If >anyone has some more information on this please let me know. I am pretty >sure I have exhausted my resources.
Re: [PHP-DB] Re: PHP and MySQL queries...
Ok here is the script after changes... Name: ".$row['fname, lname']."\n"; if (mysql_num_rows($results) ) { while( $row = mysql_fetch_array($result) ) { } } else { print "No rows found"; } ?> And now I get a parse error on line 201 which is below the html and php code, so there isn't anything to change. Please help? "Rick Emery" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > First o all, GET RID of the 19 constructs using mysql_result(). You've > already captured the row with the $row=mysql_fetch_array(). > mysql_result() cannot be mixed with mysql_fetch_arry(). > > So instead of: > echo "Address: "; > printf(mysql_result($result,$count,"address")); > echo "\n"; > > use: > print "Address: ".$row['address']."\n"; > > Next, dates are stored in MySQL as -MM-DD. Use that format in your > input. > > Next, don't combine that "if(mysql_fetch_array())" with the "do while()" > Instead, use: > > if (mysql_num_rows($results) ) > { > while( $row = mysql_fetch_array($result) ) > { > } > } > else { > print "No rows found"; > } > > Do the above. Re-submit. Tell me the results. W'ell go from there... > > rick > > -Original Message- > From: Jason [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, October 23, 2001 12:37 PM > To: [EMAIL PROTECTED] > Subject: [PHP-DB] Re: PHP and MySQL queries... > > > As of yet I have tried all sorts for date formating for the search field to > work. I.E. 2001-10-23, 10/23/2001, 10/%/2001, 10%, %10%, etc. The date > field in the database is stored as 10/23/2001 and yet when a user enters the > date and clicks the search button it does not display the results. I am > almost certain that as the user clicks the submit button the php script is > parsing the search string (i.e. 10/23/2001) incorrectly. I believe it is > parsing the sting as 10&nsb;23&nsb;2001 or something to that effect. If > anyone has some more information on this please let me know. I am pretty > sure I have exhausted my resources. > > "Jason" <[EMAIL PROTECTED]> wrote in message > [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > > I am having a hard time setting up a form for users to enter a date in the > > format of 00/00/ (of course they would use an actual date). My form > is > > as follows... > > > > *I.E. - Format is 04/01/2001* > > Search for Ads by date: > > > > > > > > > value="Submit"> > > value="Reset"> > > > > > > > > On my search.php page I have the following MySQL connection and search > > parameters... > > > > > mysql_connect ("db_hostname", "db_username", "db_password"); > > > > mysql_select_db ("db_name"); > > > > if ($date == "") > > {$date = '%';} > > > > $result = mysql_query ("SELECT > > > fname,lname,address,city,state,zip,phonea,phone,email,crty,crnum,crmo,cryr,w > > eeks,ogden,rock,logan,ipaddress,ad,total,num,date,time > > FROM ads WHERE date LIKE '%$date%' LIMIT 0, 30 "); > > $count = -1; > > if ($row = mysql_fetch_array($result)) { > > $count ++; > > do { > > echo "Name: "; > > printf(mysql_result($result,$count,"fname")); > > echo " "; > > printf(mysql_result($result,$count,"lname")); > > echo "\n"; > > > > echo "Address: "; > > printf(mysql_result($result,$count,"address")); > > echo "\n"; > > > > echo "City: "; > > printf(mysql_result($result,$count,"city")); > > echo "\n"; > > > > echo "State: "; > > printf(mysql_result($result,$count,"state")); > > echo "\n"; > > > > echo "Zip: "; > > printf(mysql_result($result,$count,"zip")); > > echo "\n"; > > > > echo "Phone: ("; > > printf(mysql_result($result,$count,"phonea")); > > echo ") "; > > printf(mysql_result($result,$count,"phone")); > > echo "\n"; > > > > echo "Email: "; > > printf(mysql_result($result,$count,"email")); > > echo "\n"; > > > > echo "Credit Type: "; > > printf(mysql_result($result,$count,"crty")); > > echo "\n"; > > > > echo "Credit Number: "; > > printf(mysql_result($result,$count,"crnum")); > > echo "\n"; > > > > echo "Credit Card Date: "; > > printf(mysql_result($result,$count,"crmo")); > > echo " "; > > printf(mysql_result($result,$count,"cryr")); > > echo "\n"; > > > > echo "Weeks: "; > > printf(mysql_result($result,$count,"weeks")); > > echo "\n"; > > > > echo "town1: "; > > printf(mysql_result($result,$count,"town1")); > > echo "\n"; > > > > echo "town2: "; > > printf(mysql_result($result,$count,"town2")); > > echo "\n"; > > > > echo "town3: "; > > printf(mysql_result($result,$count,"town3")); > > echo "\n"; > > > > echo "IP Address: "; > > printf(mysql_result($result,$count,"ipaddress")); > > echo "\n"; > > > > echo "Ad: "; > > > > $ad[$count] = (mysql_result($result,$count,"ad")); > > > > $ad[$count] = ereg_replace ("&a&", "'", $ad[$count]); > > $ad[$count] = ereg_rep
RE: [PHP-DB] Re: PHP and MySQL queries...
First o all, GET RID of the 19 constructs using mysql_result(). You've already captured the row with the $row=mysql_fetch_array(). mysql_result() cannot be mixed with mysql_fetch_arry(). So instead of: echo "Address: "; printf(mysql_result($result,$count,"address")); echo "\n"; use: print "Address: ".$row['address']."\n"; Next, dates are stored in MySQL as -MM-DD. Use that format in your input. Next, don't combine that "if(mysql_fetch_array())" with the "do while()" Instead, use: if (mysql_num_rows($results) ) { while( $row = mysql_fetch_array($result) ) { } } else { print "No rows found"; } Do the above. Re-submit. Tell me the results. W'ell go from there... rick -Original Message- From: Jason [mailto:[EMAIL PROTECTED]] Sent: Tuesday, October 23, 2001 12:37 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] Re: PHP and MySQL queries... As of yet I have tried all sorts for date formating for the search field to work. I.E. 2001-10-23, 10/23/2001, 10/%/2001, 10%, %10%, etc. The date field in the database is stored as 10/23/2001 and yet when a user enters the date and clicks the search button it does not display the results. I am almost certain that as the user clicks the submit button the php script is parsing the search string (i.e. 10/23/2001) incorrectly. I believe it is parsing the sting as 10&nsb;23&nsb;2001 or something to that effect. If anyone has some more information on this please let me know. I am pretty sure I have exhausted my resources. "Jason" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > I am having a hard time setting up a form for users to enter a date in the > format of 00/00/ (of course they would use an actual date). My form is > as follows... > > *I.E. - Format is 04/01/2001* > Search for Ads by date: > > > > value="Submit"> > > > > > On my search.php page I have the following MySQL connection and search > parameters... > > mysql_connect ("db_hostname", "db_username", "db_password"); > > mysql_select_db ("db_name"); > > if ($date == "") > {$date = '%';} > > $result = mysql_query ("SELECT > fname,lname,address,city,state,zip,phonea,phone,email,crty,crnum,crmo,cryr,w > eeks,ogden,rock,logan,ipaddress,ad,total,num,date,time > FROM ads WHERE date LIKE '%$date%' LIMIT 0, 30 "); > $count = -1; > if ($row = mysql_fetch_array($result)) { > $count ++; > do { > echo "Name: "; > printf(mysql_result($result,$count,"fname")); > echo " "; > printf(mysql_result($result,$count,"lname")); > echo "\n"; > > echo "Address: "; > printf(mysql_result($result,$count,"address")); > echo "\n"; > > echo "City: "; > printf(mysql_result($result,$count,"city")); > echo "\n"; > > echo "State: "; > printf(mysql_result($result,$count,"state")); > echo "\n"; > > echo "Zip: "; > printf(mysql_result($result,$count,"zip")); > echo "\n"; > > echo "Phone: ("; > printf(mysql_result($result,$count,"phonea")); > echo ") "; > printf(mysql_result($result,$count,"phone")); > echo "\n"; > > echo "Email: "; > printf(mysql_result($result,$count,"email")); > echo "\n"; > > echo "Credit Type: "; > printf(mysql_result($result,$count,"crty")); > echo "\n"; > > echo "Credit Number: "; > printf(mysql_result($result,$count,"crnum")); > echo "\n"; > > echo "Credit Card Date: "; > printf(mysql_result($result,$count,"crmo")); > echo " "; > printf(mysql_result($result,$count,"cryr")); > echo "\n"; > > echo "Weeks: "; > printf(mysql_result($result,$count,"weeks")); > echo "\n"; > > echo "town1: "; > printf(mysql_result($result,$count,"town1")); > echo "\n"; > > echo "town2: "; > printf(mysql_result($result,$count,"town2")); > echo "\n"; > > echo "town3: "; > printf(mysql_result($result,$count,"town3")); > echo "\n"; > > echo "IP Address: "; > printf(mysql_result($result,$count,"ipaddress")); > echo "\n"; > > echo "Ad: "; > > $ad[$count] = (mysql_result($result,$count,"ad")); > > $ad[$count] = ereg_replace ("&a&", "'", $ad[$count]); > $ad[$count] = ereg_replace ("&q&", "\"", $ad[$count]); > $ad[$count] = ereg_replace ("&p&", "%", $ad[$count]); > $ad[$count] = ereg_replace ("&bs&", "\\", $ad[$count]); > > > echo $ad[$count]; > echo "\n"; > > echo "Total: "; > printf(mysql_result($result,$count,"total")); > echo "\n"; > > echo "Ad Number: "; > printf(mysql_result($result,$count,"num")); > echo "\n"; > > echo "Date: "; > printf(mysql_result($result,$count,"date")); > echo "\n"; > > echo "Time: "; > printf(mysql_result($result,$count,"time")); > echo "\n"; > > } while($row = mysql_fetch_array($result)); > > } else {print "Sorry, no records were found!";} > > ?> > So far I have come to the conclusion that the input from the user is > probably where my problem is