Re: [PHP] Newbie question, Which way is best?

2008-03-20 Thread George J

Thiago Pojda [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 De: George J [mailto:[EMAIL PROTECTED]

 So calling the script via the form works i.e it passes the
 neccessary variables to constrct the sql query for the next
 call.

 As Shawn said, if you really need the query again add it to session, 
 never,
 NEVER give the user the ability to see/execute queries by himself 
 (remember
 POST data could be easily manipulated). Remember what Daniel said, adding 
 a
 DELETE FROM is not hard and veeery bad
OK. I see the logic.

 Ok, let me ask you something. Why post to itself? You could have a script
 only to do form actions, that way you can:
 1 Separate huge php validations with your html form.
 2 Use functions to handle the incoming data and writing the new query (or
 the old one again).

I suspect that most folk in my position start the learning process by 
finding a script that does a similar task and adapting it. This is basically 
what I've done. I started by finding a form example and then added a 
pagination routine then... Several deadends later... Not the best way to 
write anything but the simplest of scripts. However, the numerous changes to 
the code has entailed lots of learning during the process. So in answer to 
your question. I didn't set out with any idea of the best way to write the 
script. Just a broad idea of what I wanted to end up with.

 As it's built at server side, the user is never going to see your query or
 [1]manipulate it as you're writing it all over again, just using your old
 parameters (they could be added as hidden fields in the form if strictly
 necessary).


 So, as I see it, the pagination links won't POST the form
 variables. How do I pass the 'SELECT * FROM mytable WHERE
 selection=option LIMIT start, range'
 query to the called script?

 You should try building a default query where you only add the parameters
 given by the user. If you can't seem to recover that, add them to 
 $_SESSION
 and you'll be fine next time you want them (if you don't overwrite it 
 =] ).

My query code-

---SQL query construction block
  $query = SELECT * FROM prods ;
  if($catagory != 0){   // 
if category != 0
 $where=WHERE c = $catagory ;
 if ($manu != 0){  // check 
manu != 0
$and = AND m = $manu ;
if ($searchstring != 0){
   $and = $and.AND description LIKE \%$searchstring%\ ; // 
check like != 0
}
 }else{
...
$query=$query.$where.$and.$like

---
Can you please explain your suggestion above in laymans terms. I can't see 
what you have in mind. Is it your suggestion to use one script, containing a 
from, that calls another script that handles my query construction? That far 
I follow you but what happens next?




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Newbie question, Which way is best?

2008-03-20 Thread George J
Hi Shawn,

 My query code-

 ---SQL query construction block
   $query = SELECT * FROM prods ;
   if($catagory != 0){ 
 //
 if category != 0
  $where=WHERE c = $catagory ;
  if ($manu != 0){  // 
 check
 manu != 0
 $and = AND m = $manu ;
 if ($searchstring != 0){
$and = $and.AND description LIKE \%$searchstring%\ ; 
 //
 check like != 0
 }
  }else{
 ...
 $query=$query.$where.$and.$like

 ---
 Can you please explain your suggestion above in laymans terms. I can't 
 see
 what you have in mind. Is it your suggestion to use one script, 
 containing a
 from, that calls another script that handles my query construction? That 
 far
 I follow you but what happens next?



 What file is this?  is the pagination code in this file also?  If not
 where?  Post you pagination code and this is a simple explanation.

 Build your query as you've done and stick it in a session var.  It is
 now available to future calls to this page or other pages.

 -Shawn

The above code was included in post to show how query is constructed.

Heres my pagination code.
---
if($page  1){ // if number of pages  1 then display 'Previous' button
$pageprev = $page-1;
   echo(a href=\display_products.php?page=$pageprev\img 
src=\btnprevenabled.gif\ ALT=\Previous\ border=\0\ /a );
}else{
echo(img src=\btnprevdisnabled.gif\ ALT=\Previous\border=\0\ 
  );
}
//
$numpages = $totalrows / $show; //$show holds number of items to display per 
page
// display a button for each page with current page showing disabled button
for($i = 1; $i = $numpages; $i++){
   $str1=btn_;
   $str2=$i;
if($i == $page){
 $str3=$str1.$str2.disabled.gif;
  echo(img src=$str3 border=\0\ );
}else{
 $str3=$str1.$str2._enabled.gif;
echo(a href=\displayproducts.php?page=$i\img src=$str3 
border=\0\ /a );
 }
}
// if last page is less than full
if(($totalrows % $show) != 0){
   $str2=$i;
  if($i == $page){
 $str3=$str1.$str2.disabled.gif;
  echo(img src=$str3 border=\0\ );//$i );
}else{
 $str3=$str1.$str2.enabled.gif;
  echo(a href=\displayproducts.php?page=$i\img src=$str3 
border=\0\ /a );//$i/a );
}
}
// Display the enabled or disabled 'Next' button
if(($totalrows - ($show * $page))  0){
  //$str3=$str1.$str2.disabled.gif;
$pagenext =$page+1;
echo(a href=\displayproducts.php?page=$pagenext\img 
src=\btnnextenabled.gif\ border=\0\ /a);//$i/a );
}else{
   $pagenext =$page+1;
echo(img src=\btnnextdisabled.gif\ ALT=\Next\border=\0\  
);
}
?
/td/font/tr/table
---

Thanks for sticking with me.

George



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Newbie question, Which way is best?

2008-03-19 Thread George J
Hi,

I have a script that contains a form and a pagination routine that calls 
itself. I want to pass an sql query along with some other variables to the 
called script. The code to acheive this, using the form, is working but when 
I try to write the code, using the scripts URL to call itself, I am having 
problems successfully passing the SQL query string within the url.

The form is used to construct a string containing a sql query. Whereas when 
the pagination calls the script all it does is changes the LIMIT part of the 
sql query. I know it won't pass the original query unless I add it to the 
URL address.

Is there a 'proper' way to write this code? Should I add the query to the 
URL or is there a better way?

TIA
George 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Newbie question, Which way is best?

2008-03-19 Thread George J
Hi Daniel,

WHOA!  Passing the SQL query via a URL is a Very Bad Idea[tm]!

As a newbie I just have to ask why. I suspect you're going to say it gives 
the table and field names used in my database. I'm not really aware of all 
the possible avenues that this method might open up. It just feels wrong to 
include these details. This is the reason I've asked for help.

The form part of the script works fine so can we ignore that or does it 
impact on the pagination code that I'm having trouble with.

When the form calls the script it passes all the parameters that the script 
uses to construct a SELECT query. This works fine.

When the pagination calls the script it passes a new page number. This works 
fine but is where my limited experience lets me down. I need to pass the 
SELECT query, as is, back to the same script with a way to change just the 
LIMIT part of the query. Changing the LIMIT parameters simple lets me 
display another page of the returned query. I can do this change prior to 
call but what options have I on including the query in my call. Could I 
camouflage the query parameters in an array for example?

George








-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: Re: [PHP] Newbie question, Which way is best?]

2008-03-19 Thread George J
Hi Shawn,

Shawn McKenzie [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 George J wrote:
 Hi Daniel,

WHOA!  Passing the SQL query via a URL is a Very Bad Idea[tm]!

 As a newbie I just have to ask why. I suspect you're going to say it 
 gives
 the table and field names used in my database. I'm not really aware of 
 all
 the possible avenues that this method might open up. It just feels wrong 
 to
 include these details. This is the reason I've asked for help.

 The form part of the script works fine so can we ignore that or does it
 impact on the pagination code that I'm having trouble with.

 When the form calls the script it passes all the parameters that the 
 script
 uses to construct a SELECT query. This works fine.

 When the pagination calls the script it passes a new page number. This 
 works
 fine but is where my limited experience lets me down. I need to pass the
 SELECT query, as is, back to the same script with a way to change just 
 the
 LIMIT part of the query. Changing the LIMIT parameters simple lets me
 display another page of the returned query. I can do this change prior to
 call but what options have I on including the query in my call. Could I
 camouflage the query parameters in an array for example?

 George



 Maybe add your query as a session var.  Depends upon how your app works.
 Is the pagination a series of links with get vars?

 // your script that receives post data
 session_start();

 if(!empty($_POST)) {
 $query = Build query from post vars;
 $_SESSION['query'] = $query;
 } else {
 $query = $_SESSION['query'];
 }
 //  use your query

 Then there's the pagination stuff, but we'd need to see how you do it.

 -Shawn

My code checks the POSTed values
---
 if (isset($_REQUEST['selected_manu'])){
 $find_manu=$_POST['selected_manu'];
---

Yes, my pagination routine uses a series of links.

I'll underlline that I'm not only learning php but also HTML. I'm trying to 
keep things simple as there is so much to learn. I'm starting from scratch 
and find the coding fairly straightforward. However, selecting the 
appropriate techniques is another matter.

George 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: algorithm of pages beaking

2008-03-19 Thread George J
Hi,

I'm trying to resolve an issue with a pagination routine. Sounds like we're 
working on a similar routine. I have a query returning products from a 
database and then display the results in a defined number of products per 
page.

Checkout - 'Newbie question, Which way is best?' in this newsgroup.

George




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: MySQL Group?

2008-03-19 Thread George J
Hi John,

John Taylor-Johnston [EMAIL PROTECTED] wrote in 
message news:[EMAIL PROTECTED]
 Does anyone know of a good MySQL group?
 I want to make a relational link from `data` to `shopping` so when I 
 insert a new record in `shopping`, I will see the contents of
 `data`.`name` and `data`.`email` as a drop-down menu in `shopping`.

 Where does one go to get this kind of help?

 Thanks,
 John


 DROP TABLE IF EXISTS `data`;
 CREATE TABLE `data` (
   `id` int(5) NOT NULL auto_increment,
   `name` varchar(255) NOT NULL,
   `email` varchar(255) NOT NULL default '',
   PRIMARY KEY  (`id`)
 ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

 INSERT INTO `data` VALUES(1, 'Allen, Carolyn', '[EMAIL PROTECTED]');
 INSERT INTO `data` VALUES(2, 'Atwood, Margaret', 
 '[EMAIL PROTECTED]');

 DROP TABLE IF EXISTS `shopping`;
 CREATE TABLE `shopping` (
   `id` int(5) NOT NULL auto_increment,
   `name` varchar(100) NOT NULL,
   `address` varchar(100) NOT NULL,
   `email` varchar(100) NOT NULL,
   PRIMARY KEY  (`id`)
 ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=0 ;

I'm not certain but think you need to include a 'references 
table_name(field_name)' clause that sets up the Foreign key relationship 
between the 2 tables. I think the Reference clause would replace the 
auto_increment in your primary key of the referencing table.

HTH
George 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php