Need help for a query that makes a table to depend of another table to execute.

The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Need help for a query that makes a table to depend of another table to execute.

The first query is put in an Ul at the left side of the web page that contain three kind of shoes,

HTML Code:

<ul><li>
Sneakers
Dress shoes
Boots</li></ul>

Then the second query presents a table of the sneakers, dress shoes or Boots, or whatever kind you click on the <ul>, in other words the content of the second query will depend on the kind of shoe you choose or click on from the <ul> at the left side of the page similar to the illustration above. Now what I am trying to accomplish is to JOIN the two queries, where whenever a user click on a kind of shoe on the <ul> then it presents all the kinds of that kind in the table which is going to be at the right side of the page containing the second query.

What I have done so far is to create a database with two table one named Shoe_kind and the other Shoe. in both tables I have created a field called kind_id so it can connect together. The first kind of shoe has 8 shoes and all and each shoe has the integer of (1) assigned to its kind_id field, then the second kind of shoe has 8 shoes as well and each shoe has the integer of (2) assigned to its kind_id field, and so on.... but so far I haven't get them connected, what am I missing? so that when a user click on a kind of shoes all the shoes kinds of that specific kind appears according to the relationship they have through the kind_id field.

In your database kind_id is an integer, yes? like, 1,2,3 (not a string as in "1").

This is important.

In terms of security Integers are very easy for PHP to "frisk and cleanse" (int)$kind_id will turn it into an integer, then all you have to do is make sure it is not 0 (zero) and you are assured it is at least a number ( it might be a massive number, but its not going to contain an sql injection string)

Your generated links will be the likes of:

<a href="example1.php?shoe=2">Dress shoes</a>

and lead to: Example1.php

PHP Code:

<?php

// take a good look at what is being sent, // comment it out later or delete this linevar_dump( $_GET );

It totally worked, I changed the last query and it $_GET the menu. Thank you for the comments it really helped.

PHP Code:

var_dump( $_GET );

putting this line in the code was pushing down the <td></td> but I didn't know why, the <ul> in the first query was displaying according to the kind_id field but the two last <td> as I said were being push down by 20 px; but thank that you commented it out and advised to erase that line. when I erased it then it fixed and the two last <td> in the loop were pushed up to it's normal position.

For the purpose of learning why echoing the variable $query below it the query? and what does the $_GET does in this case? does it sent it out and make the ['shoe'] available to the whole file? will I be able to used later on in I want to in the file? What it the Effect behind $_GET in
kind_id = " . (int) $_GET['shoe'] ; or this case?

var_dump is a function that you use just for debugging, along with error_reporting - yes it can throw your displays out, but the idea is that you only debug on your development server (localhost, sat in front of you now).

You turn that off, or comment it out before you FTP your files over otherwise it can give out important information to a would-be hacker.

Use this at the very top of your scripts for a while:

PHP Code:

<?php$debug = true ; //turn off on live server with false

if ( $debug ){

ini_set( 'display_errors',1 );error_reporting(E_ALL);

echo '<pre>';var_dump( $_POST );var_dump( $_GET ); echo '</pre>';

}

// rest of your script down here:

// then - something is not quite right?// take a close look at the variable

if( $debug ) var_dump( $variable_name );

?>

And it will splurge out errors with some good detail when you make the most common errors.

I wouldnt say youd use this everywhere, but when starting out, it should help you post succinct and more informed questions here that are more likely to get you a fast answer.

This is all a matter of personal preference, and you are free to do what you want, whichever way suits you ( or whichever is easiest to remember ) as long as you are consistent - easier said than done!

What would have helped you sort this out yourself would have been this line:

PHP Code:

if( $debug ) echo $query ;

and to have pasted that query into PhpMyAdmin and you would have seen this was an sql error and nothing to do with PHP.

In others words, instead of assigning a "true" to the variable $debug to false, causes to turn off on live server and giving hackers and others intruders a difficult time trying to access the information, right? Excuse me I didn't understood pretty well. bear with me please.

PHP Code:

<?php$debug = false ;

if ( $debug ){

ini_set( 'display_errors',1 );error_reporting(E_ALL);

echo '<pre>';var_dump( $_POST );var_dump( $_GET ); echo '</pre>';

}

// rest of your script down here:

// then - something is not quite right?// take a close look at the variable