Get ready for BLACK FRIDAY shopping starting in

Forums

This topic is locked

SQL Query does not show correctly on Result page

Posted 04 Jan 2005 05:55:54
1
has voted
04 Jan 2005 05:55:54 Liz Mertl posted:
Hi there!
I am working on a search form where the user searches for projects. I use PHP & MySql with Dreamweaver. The table has From Date, To Date, ID, Type of Project & Country, where the country and type are select lists. The query works fine from tghe phpmyadmin, but as soon I enter the syntax in Dreamweaver Recordset, it displays only one condition. thatis: From Date, und ignores the rest!
I am using the POST method with action = result.php and created form variables, I am not really sure of the variable Syntax in the recordset I am using the default on with is fromdate , 1, $HTTP_POST_VARS['frmdate'].
This is frustrating me like mad!!! I have read everything in MySql & PHP & Dreamweaver help, but am not getting anywhere! I know it should be some small thing which I have overlooked...


Replies

Replied 04 Jan 2005 08:06:35
04 Jan 2005 08:06:35 Chris Charlton replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>...The query works fine from the phpmyadmin, but as soon I enter the syntax in Dreamweaver Recordset, it displays only one condition...<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
I noticed that phpMyAdmin, by default, adds "LIMIT 0,30" to end of all SQL queries to quickly display results of your query. If you still have LIMIT clauses in your SQL queries then take those out. I have a tutorial here on DMXzone about SQL LIMIT clauses: <b>SQL: Speed LIMITs (Using LIMIT for Speed in Your Queries)</b> www.dmxzone.com/showDetail.asp?TypeId=2&NewsId=7044

<img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

~~~~~~~~~~~~~~~
Chris Charlton

Sr. Developer - www.fingerprintMedia.com

Edited by - ccharlton on 04 Jan 2005 08:11:08
Replied 04 Jan 2005 08:30:17
04 Jan 2005 08:30:17 Liz Mertl replied:
Thanks Chris for your reply! No it is not the case, 'cause it was not copied into Dreamweaver... I checked the tabel before to see if tghe SQL queries work, but I have a sneaking suspicion that not all my form variables are recognised... I am at this for a couple of days now... so I tried everything and checked n rechecked, redid and not getting anywhere!
Replied 04 Jan 2005 09:02:11
04 Jan 2005 09:02:11 Chris Charlton replied:
In your PHP code you say "$HTTP_POST_VARS['frmdate']", and you earlier say something, "...I am using the default on with is fromdate...", are you misspelling <i>frmdate</i> (fromdate)? I'm not sure.

If you notice the single record that is showing up could be the DW default value record, then here's an article showing how to control those defaults <i>DW MX/MX2004: Controlling Recordset Defaults</i> www.dmxzone.com/go?7072.
Replied 04 Jan 2005 16:07:22
04 Jan 2005 16:07:22 Liz Mertl replied:
no chris... I didnot misspell, and yes I have already read all the tutorials and checked all the posts before I posted my request for help... are u sure it has nothing to do with the form variable and my sxntax? I assume my runtime value is correct... back again to work1
Greetings from cold Vienna!
Replied 04 Jan 2005 21:07:08
04 Jan 2005 21:07:08 Chris Charlton replied:
Can you post your SQL code? We can start there.
Replied 05 Jan 2005 14:11:07
05 Jan 2005 14:11:07 Liz Mertl replied:
Ok, Here it is: for the search page:

&lt;?php echo "&lt;?xml version=\"1.0\" encoding=\"iso-8859-1\"?"."&gt;"; ?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;title&gt;seacrh&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;form action="" method="post" enctype="multipart/form-data" name="search" target="_self" id="search"&gt;

&lt;p&gt;
&lt;input name="fromdate" type="text" id="from_date" value="&lt;?php echo $HTTP_POST_VARS['von_datum']; ?&gt;" /&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;input name="todate" type="text" id="todate" value="&lt;?php echo $HTTP_POST_VARS['bis']; ?&gt;" /&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;select name="select"&gt;
&lt;option value="*" &lt;?php if (!(strcmp("*", $HTTP_POST_VARS['country']))) {echo "SELECTED";} ?&gt;&gt;Alles&lt;/option&gt;
&lt;option value="England" &lt;?php if (!(strcmp("England", $HTTP_POST_VARS['country']))) {echo "SELECTED";} ?&gt;&gt;England&lt;/option&gt;
&lt;option value="Frankreich" &lt;?php if (!(strcmp("Frankreich", $HTTP_POST_VARS['country']))) {echo "SELECTED";} ?&gt;&gt;Frankreich&lt;/option&gt;
&lt;option value="Spanien" &lt;?php if (!(strcmp("Spanien", $HTTP_POST_VARS['country']))) {echo "SELECTED";} ?&gt;&gt;Spanien&lt;/option&gt;
&lt;/select&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;input type="submit" name="Submit" value="Submit" /&gt;
&lt;/p&gt;
&lt;p&gt;&nbsp; &lt;/p&gt;
&lt;/form&gt;
&lt;p&gt;&nbsp;&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;

for the result page:
&lt;?php require_once('Connections/crossways.php'); ?&gt;
&lt;?php
$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($HTTP_GET_VARS['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $HTTP_GET_VARS['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

$fromdate_Recordset1 = "0000-00-00";
if (isset($HTTP_POST_VARS['frmdate'])) {
$fromdate_Recordset1 = (get_magic_quotes_gpc()) ? $HTTP_POST_VARS['frmdate'] : addslashes($HTTP_POST_VARS['frmdate']);
}
$country_name_Recordset1 = "*";
if (isset($HTTP_POST_VARS['country'])) {
$country_name_Recordset1 = (get_magic_quotes_gpc()) ? $HTTP_POST_VARS['country'] : addslashes($HTTP_POST_VARS['country']);
}
$todate_Recordset1 = "0000-00-00";
if (isset($HTTP_POST_VARS['tdate'])) {
$todate_Recordset1 = (get_magic_quotes_gpc()) ? $HTTP_POST_VARS['tdate'] : addslashes($HTTP_POST_VARS['tdate']);
}
mysql_select_db($database_crossways, $crossways);
$query_Recordset1 = sprintf("SELECT VonDatum, BisDatum, Code, Land, Fach FROM mos_crossways WHERE VonDatum &gt;= '%s' AND BisDatum &lt;= '%s' AND Land = '%s' ORDER BY VonDatum ASC", $fromdate_Recordset1,$todate_Recordset1,$country_name_Recordset1);
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $crossways) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($HTTP_GET_VARS['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $HTTP_GET_VARS['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
?&gt;
&lt;table width="100%" border="0"&gt;
&lt;tr&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;table width="100%" border="0"&gt;
&lt;tr&gt;
&lt;td&gt;from&lt;/td&gt;
&lt;td&gt;to&lt;/td&gt;
&lt;td&gt;c&lt;/td&gt;
&lt;td&gt;f&lt;/td&gt;
&lt;td&gt;l&lt;/td&gt;
&lt;/tr&gt;
&lt;?php do { ?&gt;
&lt;tr&gt;
&lt;td&gt;&lt;?php echo $row_Recordset1['VonDatum']; ?&gt;&lt;/td&gt;
&lt;td&gt;&lt;?php echo $row_Recordset1['BisDatum']; ?&gt;&lt;/td&gt;
&lt;td&gt;&lt;?php echo $row_Recordset1['Code']; ?&gt;&lt;/td&gt;
&lt;td&gt;&lt;?php echo $row_Recordset1['Fach']; ?&gt;&lt;/td&gt;
&lt;td&gt;&lt;?php echo $row_Recordset1['Land']; ?&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?&gt;

&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;?php
mysql_free_result($Recordset1);
?&gt;

Just for you to understand Von Datum means fromdate in German and Bis Datum is to date, land means country <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle> I did to add the subject but I assume if I can get the country select list to work, then i could also for the subject
Replied 05 Jan 2005 20:42:10
05 Jan 2005 20:42:10 Chris Charlton replied:
At first glance I see a few naming issues...

<u><b>Search page</b>:</u>
<font face='Courier New'>...input name="<b>fromdate</b>" type="text" id="<b>from_date</b>"</font id='Courier New'> ... usually the <i>name</i> & <i>id</i> attributes should be the same value; I also notice your results page is looking for a different POST'd var (look below).


<u><b>results page</b>:</u>
<font face='Courier New'>$HTTP_POST_VARS['<b>frmdate</b>']</font id='Courier New'>... your search page has <b>from_date</b> and <b>fromdate</b> in the search form, stick with one.

<font face='Courier New'>$HTTP_POST_VARS['<b>tdate</b>']</font id='Courier New'>...your search page has <b>todate</b> for the input field, so you'll want to change this to be what the input fields' name/id is.
Replied 06 Jan 2005 01:18:32
06 Jan 2005 01:18:32 Liz Mertl replied:
thank you!!!!!
Replied 06 Jan 2005 04:47:01
06 Jan 2005 04:47:01 Chris Charlton replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>thank you!!!!!<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

<img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

~~~~~~~~~~~~~~~
Chris Charlton

Sr. Developer - www.fingerprintMedia.com
Replied 07 Jan 2005 16:06:52
07 Jan 2005 16:06:52 Liz Mertl replied:
Chris! I got it working!!!! and without any form variables. Thanks Chris, I even understand PHP n MySL better now. Actually part of the mistakes here were due to the fact that I translated the whole thing into English, und forgot to change everything, but you hit the nail on the head, I didn't even know that the id n name should be the same and that the form variables had to have the same name! That did the trick!
Chris Charlton

Sr. Developer - www.fingerprintMedia.com

Reply to this topic