Jump to content

help with mysql+php


xNuminous

Recommended Posts

im wondering if anybody could help me... I need to make a page that displays data from a database, these are tables town and price.

Eg
Town            | Price
stevenage        5
Hitchin            6
Letchworth      10
thats how it would be displayed

i also need a page to edit/add data to this

if anyone could help/assist it would be much appreciated and credit will be given

thanks in advance, xNuminous.
Link to comment
Share on other sites

You have the tables but I do not, I can hook you up with some code to do the basic CRUD functions for each table but I would need to create the tables in my MySql database.  If the information is coming out of two tables then what I was planning on doing for you is probably not exactly what you are looking for anyhow but it would be a good start.

I don't suspect anyone here is going to be able to give you exactly what you are looking for with the info you have provided..

Regards,
John Sladek
Link to comment
Share on other sites

If Town and Price are two diferent tables in your database, I'm curious as to how on earth you're relating the price to each town.  ;) Unless you're leaving something else out. I suggest you go do some reading before tackling these things. And not just jump in blind. Doing that, will actually slow down the learning process.

Anyway, you want something to tie the two together. In this very simple example, you have two tables, where records can relate to each other via a unique identifyer such as an id.

Table = "town"
====================
[color=blue][u]      id      [/u]|[u]      town      [/u]
      1      |    Compton
      2      |    Watts
      3      |    San Diego
      4      |    Long Beach[/color]
====================

Table = "price"
====================
[color=blue][u]      id      [/u]|[u]      price      [/u]
      1      |      10
      2      |      5
      3      |      20
      4      |      15[/color]
====================

[code]<?php

  $query = $db->query("SELECT * FROM price WHERE id = '$town[id]'");
  $price = $db->fetch_array($query);

?>[/code]

I hope you can understand why I showed the above examples. And you need to write seperate functions to edit/delete. Querying the database for displaying it, is only part of what you want to do. Short of someone here doing it for you, we can't do much more than point you in the right direction. (http://www.php.net)
Link to comment
Share on other sites

hm... yeah i dunno how to explain it any better

1 database - mysql called database1

2 tables - town and price

but caesar what you said is right, sorry im not entirely sure what other information to give you

i just need the 2 tables displayed next to each other like caesars example but both next to each other

sorry for the hassle everyone and thanks for the help
Link to comment
Share on other sites

sorry im not very good with php and mysql its for a company to do with driving lessons, its done in several areas and the prices changes now and again and as you can see im not very good with php/mysql so more  than anything we need a way of editing/adding/deleting the feilds like a very simple version of phpadmin

sorry for all the problems but thanks for the help
Link to comment
Share on other sites

This would be a very simple app. Would only need a few simple SELECT, UPDATE, and DELETE statements and a few pages. nothing to difficult. Just read up on some simple principles of mysql and read up on php and how to interact with a mysql db and you should not have any problems with it. A day or two worth of reading should have you up and going.
Link to comment
Share on other sites

We would be able to help no problem, but as stated before, there is no relation from the town table to the price table

you say

stevenage - 12

but how is that going to happen. You may know stevenage is 12 but there is no way the query will know. In order for it to work you would have to create a relation

table 1 "town"
====================
      id      |      town          | priceid   
      1      |    Compton      |  1
      2      |    Watts          |  3
      3      |    San Diego    |  2
      4      |    Long Beach  |  2
====================

Table = "price"
====================
      id      |      price     
      1      |      10
      2      |      5
      3      |      20
      4      |      15
====================

now you can see that Compton is priceid 1 which is 10 and Watts is priceid 3 which is 20 and so on. You just cannot make a query with 2 tables without relating them.

Ray
Link to comment
Share on other sites

"like a very simple version of phpadmin"

Please try this..  http://www.iobe.net/proj/

If you need help with it, let me know... I have an in with the developer....

When I asked you to post the SQL to create the tables this is what I was going to run for you....


-Regards
John Sladek

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.