Forum Moderators: coopster

Message Too Old, No Replies

Dreamweaver MX / PHP / Variables

displaying variables dmwx php

         

curlykarl

5:33 pm on Dec 11, 2002 (gmt 0)

10+ Year Member



Hi

Excuse me in advance for the long winded explanation:

I have a PHP page with a single form on containing two fields, I am posting this info using the get method to another page which will query a mysql database and display the required fields.

The problem I have is only one of the variables seems to be working properly, this is the code I have.

<?php require_once('Connections/connGlobal.php');?>
<?php
$currentPage = $HTTP_SERVER_VARS["PHP_SELF"];

$maxRows_rsMirror = 10;
$pageNum_rsMirror = 0;
if (isset($HTTP_GET_VARS['pageNum_rsMirror'])) {
$pageNum_rsMirror = $HTTP_GET_VARS['pageNum_rsMirror'];
}
$startRow_rsMirror = $pageNum_rsMirror * $maxRows_rsMirror;

$colname_rsMirror = "1";
if (isset($HTTP_GET_VARS['txtmodel'])) {
$colname_rsMirror = (get_magic_quotes_gpc())? $HTTP_GET_VARS['txtmodel'] : addslashes($HTTP_GET_VARS['txtmodel']);
}
mysql_select_db($database_connGlobal, $connGlobal);
$query_rsMirror = sprintf("SELECT * FROM mirror WHERE model LIKE '%%%s%%'", $colname_rsMirror);
$query_limit_rsMirror = sprintf("%s LIMIT %d, %d", $query_rsMirror, $startRow_rsMirror, $maxRows_rsMirror);
$rsMirror = mysql_query($query_limit_rsMirror, $connGlobal) or die(mysql_error());
$row_rsMirror = mysql_fetch_assoc($rsMirror);

if (isset($HTTP_GET_VARS['totalRows_rsMirror'])) {
$totalRows_rsMirror = $HTTP_GET_VARS['totalRows_rsMirror'];
} else {
$all_rsMirror = mysql_query($query_rsMirror);
$totalRows_rsMirror = mysql_num_rows($all_rsMirror);
}
$totalPages_rsMirror = ceil($totalRows_rsMirror/$maxRows_rsMirror)-1;

$queryString_rsMirror = "";
if (!empty($HTTP_SERVER_VARS['QUERY_STRING'])) {
$params = explode("&", $HTTP_SERVER_VARS['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_rsMirror") == false &&
stristr($param, "totalRows_rsMirror") == false) {
array_push($newParams, $param);
}
}
if (count($newParams)!= 0) {
$queryString_rsMirror = "&" . implode("&", $newParams);
}
}
$queryString_rsMirror = sprintf("&totalRows_rsMirror=%d%s", $totalRows_rsMirror, $queryString_rsMirror);
?>

The variables are called txtmake and txtmodel, they are transfering across from the previous page, I can see them in the address bar like this

[mydomain.com...]

It is turning out to be an epic.

Any pointers would be appreciated.

Regards

CurlyK

jatar_k

7:14 pm on Dec 11, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I assume that txtmodel is the only one working.

What exactly do you mean by not working? Getting an error message, not selecting from db? I don't really want to read through all of it without knowing what behaviour I am looking for. :)

DW seems to write php like it writes js, ugly.

curlykarl

7:57 pm on Dec 11, 2002 (gmt 0)

10+ Year Member



Hi Jata_k

Whats happening is:

I have the two fields in the form

txtmodel
txtmake

I add data to both fields and it transfers the data across as I said in the address bar, so I assume the data is going across to the results page

It does retrieve data from the database but it is only searching on the basis of the txtmodel info.

To explain better shall I sticky you the url?

The site is not live, its a spare domain I have for testing things.

Thankyou:)

CurlyK

jatar_k

8:11 pm on Dec 11, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



as it is setup right now it is only using txtmodel.

see this

$query_rsMirror = sprintf("SELECT * FROM mirror WHERE model LIKE '%%%s%%'", $colname_rsMirror);
$query_limit_rsMirror = sprintf("%s LIMIT %d, %d", $query_rsMirror, $startRow_rsMirror, $maxRows_rsMirror);

as is the script doesn't look for $HTTP_GET_VARS['txtmake'] at all that I can see. Do you select make and model 100% of the time or can you select one or the other as well?

example queries would be

existing one
SELECT * FROM mirror WHERE model LIKE '%fiesta%'

if always selecting both and they need to match
SELECT * FROM mirror WHERE model LIKE '%fiesta%' AND make LIKE '%ford%'

if they can match one or the other
SELECT * FROM mirror WHERE model LIKE '%fiesta%' OR make LIKE '%ford%'

if they have the option to only select one field for searching you will have to construct your query based on which values have been set.

[edited by: jatar_k at 9:13 pm (utc) on Dec. 11, 2002]

curlykarl

8:36 pm on Dec 11, 2002 (gmt 0)

10+ Year Member



Hi

The user does not as yet have to fill in both text boxes, but if they fill in only the txtmodel box I get zero results from the database?

I intend to make the form in such a way that if only one box is filled in it will ask you for the other info before submitting, I haven't got that far yet.

If I understand this correctly the error is in mysql query?

Or am I missing a variable?

I'm sorry to appear such a gimp but I have only been doing this for two weeks ;)

Thank you

jatar_k

9:15 pm on Dec 11, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I would think from the code you posted that if they enter make only then you get nothing where as if they enter model only you get results.

The way the script constructs the mysql query only takes into account txtmodel, it doesn't use txtmake at all.

curlykarl

9:08 am on Dec 12, 2002 (gmt 0)

10+ Year Member



Hi

I kind of understand :( I think I need more reading

can you recommend a good book?

I have a copy of:

Dreamweaver MX:
PHP Web Development

Quite usefull but not indepth enough :)

Ta

jatar_k

5:15 pm on Dec 12, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I think I would recommend php.net

That is about as in depth as you could possibly need.

some links that might help you get started
PHP Manual [php.net]
Predefined Variables [php.net] (get and post arrays)
PHP Function Reference [php.net]
PHP MYSQL Functions [php.net]

for your mysql queries
MySQL Documentation [mysql.com]
String Comparison Functions [mysql.com]
SELECT Syntax [mysql.com]

curlykarl

9:22 am on Dec 13, 2002 (gmt 0)

10+ Year Member



Thanks :)