marcmm 0 Light Poster

thank you for taking the time to explain this indeapth. I apreciate it. I still am not sure exactly how to apply this, but I'm sure some experimentation will solve that.

In the meantime I decided to use a more primitive solution to the whole problem, and jsut relayed on form submits with clicking a button instead of a checkbox. wich redirects to a page, executs the queries, updates the DB and then redirects back to the original page. the page is not expected t ohavem ore then 10 thumbnails on it at any time, so even though it might seem like a bad idea, I tested it and it seems to work ok. I'll look to updating this in the future using this example.

In the meantime, I noticed you mentioned using code before the content of the page is loaded.

This is also something I'm interested in since I'm planning to restrict access to part of the webpage by a autentification mesage where the user should type in their username and password.

the way I imagined this was that when the user would try to access the first page of the restricted part of the page, a pupul would apear whenre he would be needed to type in his password. if the password is wrong he would be redirected to the last page he was on, if it's corect he can go on. also if he tryes to load a page after the first …

marcmm 0 Light Poster

I tryed your example... it dosen't do anything. just displays the checkboxes and clicking on them will do nothing.

marcmm 0 Light Poster

I'm having a hard time figuring out what is going on in there... but anyways... can somebody please tell me how I could get the value of a checkbox when the user clicks it?

I tryed onclick function(this.value) or on mouseup function ( this.value)

and tryed echoing it on the file the function would open...

but this.value for the checkbox ALWAYS returned "on" reguardless if it was checked or not...

wich leads me to either think that it was only executing the function ONCE when the user first clicked the checkbox and then for some reason it didn't fire no matter how many times the user would re-click it...

or that this.value always returns on for the checkbox reguardless what state it is in...

so, can anybody give me a clue about this?

marcmm 0 Light Poster

thanks for the suggestion guys... I managed to skip a lot of headakes simply by doing the entire picture upload on a separate page. and I've got the upload working, the saving of files, placing in directory, naming, saving paths to DB, and accessing them from the website.

But now one more problem remains. for the admin there needs to be a checkbox next to each image detailing weather the image will display on the website or not. basicly there's a field in the DB that is either 1 or 0 and when the images are displayed on the website they check weather that field is 1 or 0... if it's 0 the pic is not displayed whille if the value is 1 the image is displayed.

I incorporated that checkbox in the file upload area so the user can choose weather to display the image on the website or not. but naturally he needs to have an option to edit that on the same page for each individual image.

so on the same page as the image upload, I made a for loop that will display all images that have a path in the DB.

INCLUDE('conect.php');


$sql_pics = "SELECT pics.smallpic, pics.largepic, pics.vizible, pics.ID
		        FROM pics
		        WHERE (pics.ID = '$VALUEl' )";

$rez_pics = mysql_query($sql_pics) OR DIE (mysql_error());

$lines_pics = mysql_num_rows($rez_pics);

FOR ($i=0; $i<$lines_pics; $i++)
	{	

	$smallpic = mysql_result ($rez_pics, $i, 'smallpic');
	$largepic = mysql_result ($rez_pics, $i, 'largepic');

	ECHO "<A HREF = '$largepic' target='_blank'> <IMG SRC = '$smallpic' …
marcmm 0 Light Poster

I wand to give the user the ability to upload as many pictures as he wants to. at present I hava a fexed amount of browse fields wich the user can use to select pictures... the code looks something like this :

<?PHP

$max_file_size = 3000000;

ECHO "<FORM NAME=name ID=name ACTION=submit.php enctype='multipart/form-data' METHOD=post >";

... code ...

ECHO "<input type='hidden' name='MAX_FILE_SIZE' value = $max_file_size > ";

	ECHO "<input id='file1' type='file' name='file[]'><BR>";
	ECHO "<input id='file2' type='file' name='file[]'><BR>";
	ECHO "<input id='file3' type='file' name='file[]'><BR>";

... code...

ECHO "<BR><INPUT TYPE = submit NAME = submit  VALUE = 'blah '>";

ECHO "</FORM>";

?>

On the other page I have code that builds a unick name for each uploaded picture, then makes a directory and copies the selected pictures in that directory.
This part works properly.

Then I have a few lines of code that build the link to each of those files in part and uploads it in to a DB... the website then accesses those pics via the links wich it takes from the DB.

Now on the DB, the images have their own table... it has two main columns... "largepic" and "smallpic". smmallpic is the thumbnail and largepic is the image that is displayed when users click on the thumbnail to view the full pic.

Now I need to figure out a way in wich to submit these pictures in groups of two. and process them in solid groups of two too.

SO I was thinking maybe on …

marcmm 0 Light Poster

thank you for the suggestion... but it turns out that it dosen't need it... despite the fact that echoing the patch and copy pasting that in a browser dosen't work... it seems that php is somehow able to interpret it properly and the code works even with "//" in it... I have no idea how but oh well...

marcmm 0 Light Poster

I'm trying to use some dynamic path names for an image upload page. In a tutorial they had something like this:

<?PHP

$directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']); 

// this echoes something like " /foldername/ " presumbing that the php file is set inside that folder in the root.

$uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'uploaded_files/'; 

// this echoes something like this "C:/folder/subfolder//foldername/uploaded_files/"

?>

basicly when you put the two strings togheter to create the path, in this case for a temporary directory to store uploaded files, each string has an "/" at the end and beginning... so when you link them you get "...subfolder//foldername..."

Is there any way to force any of the above commands not to display one of the "/" or to somehow eliminate it in order for the path to be valid?

marcmm 0 Light Poster

I can't resubmit the page because I'm already using the submit function to send the data to another page.

the intermediar check.php page seemsi nteresting. butr I ahve no idea how to make the page automaticly redirect the user to either the submit page or back to the data entry page.

any ideas how to automaticly redirect users without them touching anything?

I know there's something like this used for a back to previous page link:

onClick='history.go(-1);return true;'

and that would be perfect for sending the user back to the previous page after stating what he needs to do to continue. but that code requires that the viewer push a button. wich I don't have ( too bad I can't link the ok button from the alert message that I would use to point out the errores.

and then there's the problem with redirecting him to the submit.php page in case all the info is corect.

how do you automaticly redirect to certain pages?

marcmm 0 Light Poster

I wish to know if there is any way to refear to an empty querry result.

I want to implement a safety measure that prevents users from entering duplicate names in a DB. so I colect the value they enter in a textbox, then I create a querry wich checks the DB's name column for values that are identical to the user inputed value.

so basicly if no result is found it should continue to add the entry to the DB.

$sql_name_Check="SELECT DISTINCT table.name
		        FROM table
			WHERE table.nume = '$name'";

	$rez_name_Check = mysql_query($sql_name_Check) OR DIE (mysql_error());

	IF ( ISNULL ($rez_name_Check) )
{
code for adding the new entry
}

SO is there any way to check if a querry result is NULL and if so to execute a series of instructions?

marcmm 0 Light Poster

ok, I have a form that submits data to a database. data that is colected from things like dropdown boxes, textboxes, checkboxes etc.

I want to put some conditions that prevent the user from submitting something that is missing important data.

I found a little tutorial that dose that, but it dosen't quite work because I neet to transfer a value from a thextbox to a function and make a check that it's not empty.

here's an example of what I would like to do ( the code obviously dose not work as is):

<HTML>
<HEAD>
<script language="JavaScript">

function ConfirmForm(N)
{
var cmp = N;

IF ( cmp != "" )
{
 return confirm("are you sure you want to submit this?");
}
ELSE 
{
 return alert("You have not fild all of the necesary fields");
}
}

</script>
</HEAD>
<BODY>

ECHO "<FORM NAME=zzz METHOD=get ACTION=something.php TARGET='lll' OnSubmit='return ConfirmForm(N);'>";

ECHO "Name: <INPUT TYPE='text' NAME=N ID=N/>";

ECHO "<INPUT TYPE = submit NAME = button_submit  VALUE = 'Submit'>";

</FORM>

</BODY>
</HTML>

I don't know how to pass value of the text box from php to the java script.

Normally I would imagine there would need to be a $GET[N] statement. but I don't know where to post it. don't think it works inside the script itself.

Can anybody tell me how to do this?

marcmm 0 Light Poster

such a simple answere. thank you. problem solved.

marcmm 0 Light Poster

I've got a simple question: how can I make an onclick return confirm event work inside PHP tags.

<HTML>
<BODY>

<a href="delete.php" OnClick="return confirm('blah blah');"> Click here </a>

<?PHP

ECHO "<a href='delete.php' OnClick='return confirm('blah blah');'> Click here </a>";

?>

</BODY>
</HTML>

the first link is a simple html link with an onclick event that displays a message that allows the user to confirm the link or cancel it. canceling it will stop the link from loading.

but when I ported it inside the php tags ( and changed the "" in the link code to ' ' in order for it to work with no errore. the return confirm event will not trigger and the page will load just as though there were no onclick event.

there has to be a way to make this work with php ( since it would be absurd for it not to work inside php tags ).

So please help me out with this.

marcmm 0 Light Poster

the database is called DBname. it contains just one table called tablename.

the table contains just two columns. a county column and a cityname column.

I would really apreciate some feedback on this guys. Please...

marcmm 0 Light Poster

Ok guys... I took the time to look over the posted solution... but I'm affraid I was not able to understand half of what was going on in there.

I fiddled around and came up with this simplistic example:

<html>
<head>
	<title>Exemplu select</title>
<script language="javascript">

function onchangeCounty()
{
	document.form1.submit();
}
</script>
</head>
<body>

<?php
	$County1 = $_GET[County];
?>

<form name="form1" METHOD=get >

	County:
	<select name="County" onchange="onchangeCounty();">
		<option value=""></option>
		<option value="name1">Name1</option>
		<option value="Name2">Name2</option>
	</select>

	<?php

	$con = mysql_connect("localhost","root","");
	if (!$con)
	{
	    die('Could not connect: ' . mysql_error());
	}
	mysql_select_db("DBname", $con);
	$select="SELECT * FROM tablename WHERE Countyname='$County1'";
	echo "<br>";
	$result = mysql_query($select);
	echo "County:";
	echo "<select>";
	while($row = mysql_fetch_array($result))
	{
		echo "<option>" . $row['Countyname'] . "</option>";
	}
	echo "</select";
	mysql_close($con);
	?>
</form>
</body>
</html>

Now this works preatty well as it is... but it needs enhancing.

First of all, the option selected in the first list dosen't stay selected when the form reloads. I am transmitting the value and it's there when the form reloads via the get methode... but I haven't the slightest clue how to force the select object to target it after it has been repopulated. Any ideas?

Secondly. this example has the form only containing the dropdown lists. but I intend to use it in a form that will contain checkboxes too. well I don't want to loose the selected checkboxes when the form reloads... so is there a way in wich to put one form inside another?

Like:

<form1>
<form2>

marcmm 0 Light Poster

Use a INNER JOIN statement in your SQL query, placing it before WHERE . You may be able to link a common ID field between the two tables and show a result into one set.

well yes... but my problem is that it's displaying the same hotel twice ( and if the prices table will have for example 4 prices atributed to the same hotel it will display that hotel 4 times ) despite there beying a DISTINCT keyword set at the beginning of the query string.

at this point I just need to prevent any duplicate posts. To the best of my knowledge DISTINCT is supposed to handle that... but for some reason it backfires in this example and I cannot understand why.

I need it to display results only once.

marcmm 0 Light Poster

Ok, I'm having a big problem with an sql string for a query.

I want to implement a methode that allows the user to search for hotels by entering the minimal price ( so if they enter say 20 it will only display hotels that have prices above 20 ).

SO I setup a textbox to colect the value then I was to create the sql string to make the query. Well at that point everything whent wrong.

Well this is my sql string B4 implementing the minimal price search:

$sql_hstring="SELECT DISTINCT tables.names
		        FROM base table, satelite1, satelite2, satelite3
			WHERE ((basetable.city = satelite1.ID )
			AND (satelite1.name = satelite2.ID)
			AND (basetable.something=satelite3.ID))
                        ORDER BY localitate.den_localitate ASC";

basicly it means I have a few many to 1 conections already in the condition area of the query. the query works perfectly at this point.

Well, the hotel prices are stored in yet another table ( because I have more then one price for a hotel ).

SO the new query would logically be like this:

$sql_string="SELECT DISTINCT tables.names
		        FROM base table, satelite1, satelite2, satelite3, prices
			WHERE ((basetable.city = satelite1.ID )
			AND (satelite1.name = satelite2.ID)
                        AND (basetable.hotel_id = prices.ID_hotel)
			AND (basetable.something=satelite3.ID))
                        ORDER BY localitate.den_localitate ASC";

The link is yet another many to 1 link... linking the unick ID hotel in the base table with a column that identifiew wich price belongs to wich hotel.

at the moment the prices table looks like this:

ID hotel_ID price
1 …

marcmm 0 Light Poster

Well I tested it and it works... so problem solved... thanks for the input guys... using the get methode and implementing the posting and retrieving of data from page to page was something I doubt I would have figured out on my own...

marcmm 0 Light Poster

Ok... I belive I fixed it... It seems to work properly now... my errore seems to have steemed from the fact that I had a few variables in highercase in some areas... and sicne var names are casesensitive... it pushed the entire system overboard...

Gona do some testing to make sure everythign works then I'll post my solution ( if nothing else comes up ).

marcmm 0 Light Poster

it still dosen't work...

6%5

and going through this:

IF ( is_float ( $pagination ) )
		{
		$total_pages = $pagination + 1;
		}

still gives 3 pages instead of 2...

And I STILL loose all my parameters when I click any of the page links... so when the page reloads and reexecutes the query it dosen't have the parameters and what happenes is that it ends up executing the query with no parameters...

the problem has to be in the transmit line:

ECHO "<a href='display.php?page=$i$pagelink'> $i </a>";

cause up untill there the strings are all fine... but once I hit any of those links... I losoe all my parameters... namelly everything contained inthe &pagelink variable...

are you sure that it's the "&" symbol that ties multyple variables to be sent with the ? symbol from page to page?

marcmm 0 Light Poster

I've noticed that the link seems to have certain problems sending the combo parameters...

they are under this form:

&combo1='number'

but the link will only say &combo1=

seems as though it has problems reading ' characters or something...

Wich means either it transmits an empty parameter to the reloaded page... or it dosen't transmit anything... reguardless... on the next page the if isset structures are not executed ( well except for the page if isset tree... that one works ).

marcmm 0 Light Poster

Unfortunatelly it still dosen't work... and the page calculation system is flawed...

here's what I have in adition to the above:

$pagination = $total_lines/$displaylines; // ( total_lines is the variable I obtained when I did the hidden query to determine how many records my query would have without the limit parameter / display lines is a var that hoalds the number of results per page wich defaults to 5 at the begining of the page. )

	IF ( is_int ( $pagination ) )
		{
		$total_pages = $pagination;
		}

	IF ( is_float ( $pagination ) )
		{
		$total_pages = $pagination + 1;
		}

	FOR ($i=0; $i<$total_pages; $i++)
		{
		ECHO "<a href='display.php?page=$i$pagelink'> $i </a>";
		}

well first of all the page count is always wrong... at present my DB hoalds just 6 entries... if just hit search and not select anything ( meaning that I want to display all the records ) the division should be 5 records on first page and 1 record on a second page...

the calculation should be:

$pagination=6/5=1.2; // that's float so it should take this route:

IF ( is_float ( $pagination ) )
		{
		$total_pages = $pagination + 1=2.2; ( is there no way to just take the integer part of a number? not rounding it )
		}

the code will display 3 pages... namelly 0 1 and 2... and their code dose not work either...

when I seelct either of them I will either loose all or part of the atributes contained …

marcmm 0 Light Poster

Ok... more progress:

$currentpage = 0; // I had to set the current page var to 0 outside the if isset loop because the else branch there dosen't seem to work

$sql_line="SELECT DISTINCT tables.names
		        FROM tables
			WHERE ((standard cond 1 )
			AND (standard cond 2 )";

$sql_end=") 
	  ORDER BY something ASC";

$sql_limit=" LIMIT $currentpage,5"; // I made the first value of the limit to point to the currentpage and the second representing how many results to display per page... 5 at the moment...

IF ( ISSET($_GET[page]) )
	{
	$currentpage = $_GET['page'];
	}
ELSE
	{
	$currentpage = 0; // this branch dosen't work... but I supose it makes sence... the page is beying sent even by default from the browse frame...
	}

IF ( ISSET($_GET[combo_1]) && $_GET[combo_1]!=0 )
	{
	$combo_1 = $_GET['combo_1'];
	$sql_line .= "AND (cond 1)";
	$pagelink .= "&combo_1 = $combo_1";
	}

IF ( ISSET($_GET[combo_2]) && $_GET[combo_2]!=0 )
	{
	$combo_2 = $_GET['combo_2'];
	$sql_line .= "AND (cond 2)";
	$pagelink .= "&combo_2 = $combo_2";
	}

IF ( ISSET($_GET[checkbox1]) )
	{
	$sql_line .= "AND ( cond3 )";
	$pagelink .= "&checkbox1 = AND ( cond3 )";	
	}

IF ( ISSET($_GET[checkbox2]) )
	{
	$sql_line .= "AND ( cond4 )";
	$pagelink .= "&checkbox2 = AND ( cond4 )";	
	}

IF ( ISSET($_GET[checkbox3]) )
	{
	$sql_line .= "AND ( cond5 )";
	$pagelink .= "&checkbox3 = AND ( cond5 )";	
	}

$sql_line .= $sql_end; // I add the order part

$sql_totallines = $sql_line; // I create the string for the hidden query

$rez_totallines = mysql_query($sql_totallines) OR DIE (mysql_error()); …
marcmm 0 Light Poster

oh... nevermind... I understand what you mean... ok... I will change it... then get started on the split pages...

marcmm 0 Light Poster

Ok... after reading the above I realised how unnecesarelly I complicated myself with the code... SO I deleted most of it and started from scratch this is how the beginning of the document looks like right now ( this is before starting to implement the split paging )

$sql_line="SELECT DISTINCT tables.names
		        FROM tables
			WHERE ((standard cond1)
			AND (standard cond2)"; 

$sql_end=") 
	  ORDER BY something ASC";

IF ( ISSET($_GET[combo_1]) )
	{
	$combo_1 = $_GET['combo_1'];
		IF ( $combo_1 <> 0 ) // check to see if user has selected something other then the default
			{
			$sql_line .= "AND (cond1)";
			}
	}

IF ( ISSET($_GET[combo_2]) )
	{
	$combo_2 = $_GET['combo_2'];
		IF ( $combo_2 <> 0 ) // check to see if user has selected something other then the default
			{
			$sql_line .= "AND (cond2)";
			}
	}

IF ( ISSET($_GET[checkbox1]) )
	{
	$sql_line .= "AND ( cond3 )";
	}

IF ( ISSET($_GET[checkbox2]) )
	{
	$sql_line .= "AND ( cond4 )";
	}

IF ( ISSET($_GET[checkbox3]) )
	{
	$sql_line .= "AND ( cond5 )";
	}

$sql_line .= $sql_end;   // I atatch the end of the sql line

this format ctually simplifyed my coding on the display page considerably... so thanks for the hint... basicly now... each time the page loads it will suposedly check to see weather any of those parameters have been sent to the page... by default they are sent by the browse frame... and next they will be sent by the page links... am I corect?

marcmm 0 Light Poster

Ok, I figured out the logic behind your earlyer post... but one question still remains...

it's easy for the dropdown list parameters since they wiull always exist... having either 0 or a value different then 0 to transmit... so those parameters would be present for every link every time reguardless of the circumstances...

but what happenes with the checkboxes? if the user dosen't select a checkbox... that parameter shouldn't exist... what do I do then?

and about the parameter list to transmit... is it viable to just keep adding parameters to it via .= so that they would be like this:

<a href='target_page.php?page=1&param1=value1&param2=&value2>1</a>

is that a viable construction? just adding ?name=$name over and over ( with different parameters of course ) will be recognised as multyple parameters and then I check each of them in the if issetstatement with an independent if isset statement for each of them?

marcmm 0 Light Poster

Ok... so I redefined my search button form and now it reads like this:

ECHO "<FORM NAME=hoteluri METHOD=get ACTION=display.php TARGET=result>";

ok... now on to the if ifset statement...

right now it looks like this:

if(isset($_GET['page']))
{
    $pageNum = $_GET['page'];
}


$offset = ($pageNum - 1) * $rowsPerPage;

If I understand corectly... I have to have all the code to rebuild the query inside this if statement... ( or a, I even more confuse and this is another if ifset statement different from the one that apears at the very top of the page )

Or do I have one of these if isset statements for each variable I transmit via the next/previous/number links?

Or is this just one single if isset statement wich coveres all the necesary variables needed to build the query... if so how do you handle the fact that the number of parameters needed varies ( acording to what the user selects from the browse frame )

it's a bit confusing... sorry...

if(isset($_GET['param1']))
  {
  $param1 = $_GET['param1'];
  $SQL .= 'AND whatever='.$param1;
  $pagelink .= '&param1='$param1;
  }

I'm guessing that my param 1 you are refearing to one of the variables needed to create the query... like for example one of the variables depicting the selection in a dropdown list on the browse frame.
Well if so... that means I have to copy paste the entire query building process inside this if statement... unfortunatelly that will be a lot of code since the code …

marcmm 0 Light Poster

Marcmm,

Normally the sql statement should be re-run every time with the new parameters. This is why it is good to use $_GET, instead of $_POST, because $_GET does not explicitly require a form and fields to be submitted.
What you actually need to do is always check the $_GET variables as if it is the first time you run the code.

If you want you may also check this thread
http://www.daniweb.com/forums/thread156953.html

SO when you said to use "get" in stead of "post"... were you refearign to when I submit the search parameters from the browse frame:

ECHO "<FORM NAME=hoteluri METHOD=post ACTION=display.php TARGET=result>";
...
code for several dropdown lists and checkboxes (and maybe even a textbox in the future);
...
ECHO "</FRAME>";

should I use get method when submitting these results and loading the display frame?

Or were you refearing to the way I'm requesting these results from within the display frame:

$combo_1 = $_REQUEST['combo_1 from browse frame'];
$combo_2 = $_REQUEST['combo_2 from browse frame'];

the above is requesting the variable transmited by the dropdown lists ( and to my understanding $_request is like "post" and "get" combined anyways )

Or

IF ( ISSET($_POST[checkboxname]) )
	{
	$sql_query .= "AND ( condition )";
	}

to check if the checkboxes on the browse frame have been checked.

And yes, the sql statement IS rerun everytime you click a next or previus page... but I loose all my parameters when I do so ( bolth the variables from …

marcmm 0 Light Poster

Ok... I have another problem. I have tryed to split the resultts of my query in to multiple pages with a fixed number of results per page... I used this tutorial for it:

http://www.php-mysql-tutorial.com/php-mysql-paging.php

Originally, my page worked as follows:

There was a search frame where the user would select different things through dropdown lists or checkboxes... hisselections were sent via a post method as parameters to the "display" page.

On the display page those parameters were obtained through the "$_request" or "$_post" methodes and asigned to local variables wich were then used as conditions in the query.

Now, AFTER I implemented the tutorial everything works perfectly... except one thing.

Well, let me start from the beginning:

In the new versione the parameters are still beying sent from the browse frame to the display frame via request or post and then used locally in the query string. the tutorial also implemented a limit parameter to the query determining the first page and the number of results per page.

The results are split acordingly and the corect number of pages is displayed. It also echoes next, previous and page number links for accessing the other results of the query.

well... these links look something like this:

$page = $pageNum + 1;
 $next = " <a href=\"$self?page=$page\">[Next]</a> ";

this basicly tells the page to reload itself and send the new $page variable to the reloadedpage.

When the page reloads there's …

marcmm 0 Light Poster

Ok this is weird... I tryed executing the string again today and it worked... but it wouldn't work yesturday... I don't get it...

the string dose not work with paranteses that I figured out... but I'm positive I tryed without paranteses yesturday and it did not work... and it works today... I am at a loss as to what happened... but reguardless... it was like this:

limit 0,5

I guess problem solved...

marcmm 0 Light Poster

I'm interested in the limit parameter. When ever I try to use that I get this error:

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(0,5)' at line 5"

this is the line in question:

ORDER BY table.smth ASC LIMIT (0,5)";

It's part of a query that works perfectly if I remove the limit parameter so the errore can only be here.

In some examples I have seen it used like :

ORDER BY table.smth ASC LIMIT 0,5";

or

ORDER BY table.smth ASC LIMIT 5";

But all will output the same error for me... I need the limit in order to split my query results in multyple pages... I'm folowing this tutorial BTW:

http://www.php-mysql-tutorial.com/php-mysql-paging.php

But the limit parameter just won't work for me... can anybody help please?

marcmm 0 Light Poster

Ok, thank you very much for the repply and indeed, your solution works like a charm. And it's as simple as it's efficient. I didn't think about it maybe because I was considering the querry string as a line of parameters rather then just a normal string... I mean they only turn in to parameters when you run the line that executes the querry.

So anyway what I did was like you sugested:

$sql_querry="SELECT DISTINCT tables.names
		     FROM tables
	             WHERE ((condition )
		     AND (condition)";

$sql_end=") 
	        ORDER BY localitate.den_localitate ASC";

Wanted to point out that if one is using multyple conditions it's crucial to add the ")" to the start of the end string.

Then I just implemented if statements for each checkbox:

IF ( ISSET($_POST[checkbox name]) )
	{
	$sql_querry .= "AND ( condition atatched to that checkbox )";
	}

and lastly just concatenate the two strings and execute:

$sql_querry .= $sql_end;
        $rez_querry = mysql_query($sql_querry) OR DIE (mysql_error());

also I did not know about ".=" or "isset" so this also saved me a lot of truble. I was going to look if the checkbox was set using $_REQUEST and check if the checkbox was different from 0, like I check if the user selected something other then the default value in the dropdown boes.

ANyways, thanks again for the tips, problem solved.

marcmm 0 Light Poster

guys, sorry for beying so silent over the past weeks, been flooded with other things that I didn't have time to look over that suggestion properly, but I will be looking voer ti soon and will provide feedback about weather I could or couldn't fix the problem

Please bear with me.

marcmm 0 Light Poster

Ok, I have this dilemma reguarding the building of querries.

I have a website that browses hotels. The user can select the region and the quality of the hotel via some dropdown boxes and then he is offered weather the search results should include certain options that the hotels should have... like "parking space" or "swimming pool".

I use checkboxes for each of these options. Now my problem is that I don't have the slightest idea how to handle the building of the querries in order to include these checkboxe options.

Each checkbox, when checked, is supposed to add an AND () statement to the querry's condition parameters. But if the checkboxes aren't selected that condition should not exist.

the inefficient way would be to build an extensive IF structure that would encompas all possible combinations of the checkboxes. but if you have, for example, 9 checkboxes that would result in 81 posible combinations of the querry. if you also combine that with the extra combinations added from the dropdown boxes you get madness...

There has to be an easyer way!

The querry structure when ALL the checkboxes are unselected looks something like this:

$sql_querry="SELECT DISTINCT tables.fields
		        FROM tables
			WHERE ((condition )
			AND (condition))
			ORDER BY something ASC";

now I would like to do something like this:

$sql_querry="SELECT DISTINCT tables.fields
		        FROM tables
			WHERE ((condition )
                        IF ( checkbox1 is set )
                               {
                                AND ( condition )
                                }
                         IF ( checkbox2 is set )
                               { …
marcmm 0 Light Poster

yes, still around... I was just away over the weekend...

andrei_ajder@yahoo.com

marcmm 0 Light Poster

I would apreciate it greattly.

ANd the oricare option mearly dumps ALL the options in the menue.

SO if the first menue has "any ( oricare )" selected, the second menue will display all the cathegories from all the firms. In adition if the second menue ( cahtegory ) has "any" selected, the last menue ( subcathegory ) will have all subcathegories selected from all the cathegories from all the firms.

If you select a firm in the first menue and any in the second menue, the second menue will be populated with all the cathegories from the single selected firm. Likewise if you select a cathegory from the second menue the third menue should be populated only with the subcathegories of the single selected cahtegory.

The any option should remain present no matter what selection you make, in every menue.

The any option however is a key in the display process, because it determines what gets printed when the search button is clicked under the dropdown lists.

The code contains 9 if statements to cover ANY possible combination between the three dropdown lists ( to check weather "any" is selected ):

// this code is situated on another php file inclouded in the file in wich the dropdown lists are created. It seems to refear to the drobdown list objects as superglobals with the $_request function ( though I am not entierly sure, as changing either the name or the ID of the …
marcmm 0 Light Poster

Yes indeed, there are only 3 menues. Threre is NO "product" menue.

The site sems to use superglobals ( via $_REQUEST) to link to the dropdownlist objects ( from the page that displays the results ) and store what ever is selected in variables wich are later on used in conditionals to determine weather the user has modifyed the standard option ( namelly to display all ). then based on that, the results are displayed in a table on a different frame then the dropdown lists.

SO in the end yes, there are ONLY 3 MENUES:

Firm ( static, not influenced by anything )
Cathegory ( influenced by firm )
Subcathegory ( influenced by firm and cathegory )

and the chalange is the make those three menues dynamicly linked. If it's possible to do it only via javascript it would be nice, since it wouldn't require the instalation of aditional softwere on the server the site will be running from...

marcmm 0 Light Poster

P.S.

for the integrity of the remaining code, the first option in each of the three dropdown lists must be "Oricare" ( everything ), wich is later used in determining weather the user sleected something from the dropdown lists or just left the default values wich are coded to display the entire list of products.

marcmm 0 Light Poster

well, the database is preatty extensive ( I did not build the database ), but I will try to give a description of those tables in the DB that are conected with this particular process.

The main table seems to be one called "product" wich has the following columns:

ID ( primary key )
productname
id_firm ( key )
id_cathegory ( key )
id_subcathegory ( key )
productdescription
oldprice
newprice
circulatingmedium
logo
date
display ( a variable used in the original queries as a condition )

Then there's the "firm" table:

ID ( primary key - linked with id_firm in product table )
firmname ( displayed in the firm dropdown list )
logo

Then there's the "cahtegory" table:

ID ( primary key - linked with id_cathegory in product table )
cathegoryname ( what is displayed in the cathegory dropdown list )

Then there's the "subcathegory" table:

ID ( primary key - linked to id_subcathegory in the product table )
cathegory ( key - linked with ID in cathegory table )
subcathegory name ( what is displayed in the subcathegory dropdown list )

There are obviously more tables invoulved in the DB, but these seem to be the only ones that this particular feature uses, or should use.

Let me know if you need further explanations. My original post in the topic shows how the …

marcmm 0 Light Poster

Ok, well I understood how your example works... basicly, I'm still having problem with the syntax, and recursivity is an anoyance ( didn't really like it back when I was doing C++, don't like it now either, but hey, if it gets the job done... ).

Now, I would have one more question reguarding this example, it works out perfectly and it's just what I'm looking for, so I'm going to try and apply this to my problem, but there's a catch, I have noticed that you actually whent and hard-coded all the possible combos. Now it's preatty simple with so few options, but I would imagine that the amount of code would increase to staggering proportions for more options, not to mentione that each time the database is changed ( adding new fields, removing or modifying existing fields ) would mean that one would have to go in the page code too and modify the code acording to the database changes.

Just upkeeping the table of possible combos would be a titanic job. There must be a way in wich to automate that process, so that the combos would be generated automatically reguardless of what data you are importing from the database.

SO far, as I posted in my original topic, I'm gettign the data out of the database through queries, wich I am storing in arrays, and then asigning the values of the arrays directly in to the menues ( I'm guessing that this code …

marcmm 0 Light Poster

I thank you all for taking the time to repply, but as I said I am very new to the whole web programming thing. I just whent over basic PHP and html. I haven't done any javascript, or dabbled with the use of other plug-ins like this ajax everybody seems to mentione. That's why I asked if it was possible to achieve this dynamism using just php alone.

I guess it's not possible to do that in php. SO I guess I have to branch out in to javascript too. I would like to experiment with the example you provided, but embarassed as it makes me, I don't even know how to make it run.

Thous far I have been using a softwere called wampserver that incloudes bolth apache and mysql. ANd with php/html it was relativelly easy as I ran everything through localhost/filename.extension ( be it php or html ). BUt I honestly have no clue how to run files that contain javascripts. I know there's jscript files with the js extension... but that dosen't work because if I save the file like that the browser will just display the code. ( by the way i'm using notepad to write my code ).

So if you could point me in the right direction I would apreciate it...

Linking objects dynamicly seemed like such a simple thing at first, and it's turning in to a real nightmere the more you learn about it.

marcmm 0 Light Poster

Yes indeed I figured that reloading the whole page is not a good idea cause that in the end would reset the fields too, so I don't think it's even a possible solution.

As stated before, I was thinking of using something like onchange ( if php has something like that ) to detect when a dropdown list has been modifyed. then take the selection from that list ( I have no idea how to referance a list selection in php... in clasic programing it was objectname.property... ) and store it in a variable.

The actual queries would have an if else statement that would detect if the user selected something from the lists ( the dropdown lists all default to showing everything, so if the selection is not equal to the standard, it would make a querry using the value stored in the variable mentioned earlyer in the condition. and if the user did not select anything, or he selected the default item it would do the default querry I listed in my original post. )

Then all that would be left would be a way in wich to re-trigger the querry execution ( not reload the whole page obviously, cause then all the stored data would be lost and all variables would reset to their default values ).

This is the solution I imagined for this, but I have no idea if what I desccrived above is even remptly possible.

Basicly I'm searching …

marcmm 0 Light Poster

Hello, I am fairly new to PHP, having just started messing around with it, but I need to solve something and I would apreciate any help any of you could offer.

Here is my problem:

There's a hardware online store built using php/html and connected to a mysql database.

It has a search function that consists of three dropdown boxes, one for firm, the second for product type, and the third for subproduct.

What I want is to make those dropdown boxes interconected, so if I select something from the first list ( the firm list ) the second dropdown box will be RE-populated with only the types of products that that firm produces ( same connection between the second and third ).

As it is now, the dropdown boxes are populated by querries, like this one ( this is for the items that will be placed in the firm dropdown box ):

$sql_combo_firma="SELECT DISTINCT firme.ID, firme.denfirma 
		  FROM firme, produse 
		  WHERE ((produse.id_firma=firme.ID) AND (produse.afisare='-1')) 
		  ORDER BY firme.denfirma ASC";

and this is for the product dropdown box:

$sql_combo_categorie="SELECT DISTINCT categorie.ID, categorie.dencategorie 
		      FROM categorie, produse 
		      WHERE ((produse.id_categorie=categorie.ID) AND (produse.afisare='-1')) 
		      ORDER BY categorie.dencategorie ASC";

Then I proceed to execute the queries:

$rez_combo_firma = MYSQL_QUERY($sql_combo_firma) OR DIE (mysql_error());
$rez_combo_categorie = MYSQL_QUERY($sql_combo_categorie) OR DIE (mysql_error());

and I count how many rows the queries have:

$linii_firma = MYSQL_NUM_ROWS($rez_combo_firma);
$linii_categorie = MYSQL_NUM_ROWS($rez_combo_categorie);

then a proceed to populate the dropdown lists:

ECHO "<SELECT NAME=combo_firma
			      ID=combo_firma 
			      STYLE='font-family: Arial; 
			      		FONT-STYLE: normal; 
				      FONT-SIZE: 11; 
				      COLOR: #000000; …