Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Need help :)


  • Please log in to reply
24 replies to this topic

#1 anton-shirikov

anton-shirikov

    CC Newcomer

  • Just Joined
  • PipPip
  • 21 posts

Posted 08 November 2007 - 02:46 AM

Hello, I am new here.
I am preaty new in PHP programming, so need some help

I need to make a database! It would work same as this form:

The problem is i am not sure how to make that choosing. I mean how can i make that if i choose for example Astom Matrin, in model there would be aston martin models in 3) and so on...

So if anyone can help me that would help a lot :)
  • 0

#2 anton-shirikov

anton-shirikov

    CC Newcomer

  • Just Joined
  • PipPip
  • 21 posts

Posted 08 November 2007 - 02:46 AM

Here is link, in first post it didn't let me add it:
Kroon-Oil BV
  • 0

#3 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 08 November 2007 - 06:40 AM

Well it really has to do with how you set up your database table, a good idea might be:
|    id    |   make    |    model    |    type    |
-------------------------------------------
|    1     |Alfa Romeo|     145     |      1.3    |
-------------------------------------------
|    2     |Alfa Romeo|     145     |      1.4    |
-------------------------------------------
|    3    |     Aro   |      10     |      1.9D   |
Then the first menu would be a simple query like:
"SELECT `make` FROM `db_table`"
//more code
echo $row['make']


Then that selection would be used to query the next menu:
"SELECT `model` FROM `db_table` WHERE `make`='previous_result'"
//more code
echo $row['model']


Then that selection would be used to query the next menu:
"SELECT `type` FROM `db_table` WHERE `model`='previous_result'"
//more code
echo $row['type']

  • 0

#4 anton-shirikov

anton-shirikov

    CC Newcomer

  • Just Joined
  • PipPip
  • 21 posts

Posted 08 November 2007 - 10:33 AM

hmm. So this will work preaty much same as on that site ? :)
If yes than that's exactly what i need :P
  • 0

#5 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 08 November 2007 - 12:10 PM

yes, it will work exactly as that site
  • 0

#6 anton-shirikov

anton-shirikov

    CC Newcomer

  • Just Joined
  • PipPip
  • 21 posts

Posted 09 November 2007 - 02:20 AM

kk gonna try this today :)
Ty a lot
  • 0

#7 anton-shirikov

anton-shirikov

    CC Newcomer

  • Just Joined
  • PipPip
  • 21 posts

Posted 09 November 2007 - 03:34 AM

I started working at this and got a problem.
I am trying to make a select. Here is the code:
<font color="#ff6600">Выберити тип автомобиля: </font><select class="mini" name="cat">
<option class="mini" value="">...................................................................</option>
<?php
$query = "SELECT 'cat' FROM 'cars'";
$result = mysql_query($query, $connection);

for($i=0; $i < mysql_num_rows($result); $i++)
{
$cat= mysql_result($result, $i, "cat");

echo "<option class = \"mini\" value=\"$i\">$cat</option>";
}
?>
</select>


And this doesn't actualy work. Hmm can anyone help again ? :D
  • 0

#8 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 09 November 2007 - 07:49 AM

Have you actually made a connection to your database? Try displaying the mysql error.

$result = mysql_query($query, $connection) or die(mysql_error()); 

  • 0

#9 anton-shirikov

anton-shirikov

    CC Newcomer

  • Just Joined
  • PipPip
  • 21 posts

Posted 09 November 2007 - 08:00 AM

Yes i did. This is just part of code. There is another <?php there. Here it is:
<?php
require($_SERVER["DOCUMENT_ROOT"]."/xenum/config/db_config.php");
$connection = @mysql_connect($db_host, $db_user, $db_password) or die("Error connecting");
mysql_select_db($db_name, $connection);
?>


and here is db_config.php

<?php
$db_host = "localhost";
$db_user = "Anton";
$db_password = "f00";
$db_name = "xenum";
?>

  • 0

#10 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 09 November 2007 - 08:07 AM

As I mentioned before, try displaying an error from the query:

$result = mysql_query($query, $connection) or die(mysql_error()); 

  • 0

#11 anton-shirikov

anton-shirikov

    CC Newcomer

  • Just Joined
  • PipPip
  • 21 posts

Posted 09 November 2007 - 08:09 AM

yeah i did... Well it doesn't show any kind of error. only deleted all other "<tr>" in Table. So delete all other information.
  • 0

#12 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 09 November 2007 - 10:50 AM

This is how I query a database - and if there are no errors with your connection, than this should work:

<?php
$query = "SELECT `cat` FROM `cars`";
$result = mysql_query($query);

while($row = mysql_fetch_assoc($result)) {
echo $row['cat'];
echo "<br />";
}
?>


And that should echo your results...
  • 0




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download