/    Sign up×
Community /Pin to ProfileBookmark

PHP Two-tables in select statement…help!

Hello,

I seem to be having some problems with my site.

I have several tables that store data on items added. If I want to edit an item, it is easy to edit it when the data is in the ‘items’ table, but because I’m using different tables for other parts, it doesn’t seem to like it.

Any ideas ?

UPDATE QUERY

[code=php]
$query = “UPDATE items SET name=’$itemname’, label=’$label’, type=’$type’, stype=’$stype’, qty=’$qty’, uksize=’$uksize’, ussize=’$ussize’, eusize=’$eusize’, colour=’$colour’, condition=’$condition’, material=’$material’, description=’$descr’, rrp=’$rrp’, price=’$price’, pandp=’$pandp’ WHERE id = $id”;
$result = @mysql_query ($query); // Run the Query[/code]

SELECT QUERY

[code=php]$query = “SELECT i.id, i.type, i.label, t.id, t.type, l.id, l.name, i.name, i.description, i.price, i.date, s.stype, i.qty, i.uksize, i.colour, c.id, c.colours, i.condition, i.material, i.rrp, con.id, con.condition, m.id, m.material, i.ussize, i.eusize, i.largeimageone, i.pandp, s.id FROM items as i, type as t, label as l, stype as s, colour as c, condition as con, material as m WHERE i.type = t.id AND i.label = l.id AND i.stype = s.id AND i.colour = c.id AND i.condition = con.id AND i.material = m.id AND i.id = $id”;
$result = mysql_query($query); // Run the Query.

if (mysql_num_rows($result) == 1) { // Valid ID, show the form.

// Get the user’s information.
$row = mysql_fetch_array($result, MYSQL_NUM);
[/code]

SELECT

[code=php]<select name=”type” size=”1″>
<option></option>
‘.”n”;

$type = array(‘footwear’,’clothing’,’mens’,’bargain’,’ladies’,’kids’,’football’,’misc’,’wholesale’,’joblots’);

for($i = 0, $j = count($type); $i < $j; $i++){
echo ‘<option value=”‘.$type[$i].'”‘.(($type[$i] == @$row[4])?’ selected=”selected”‘:”).’>’.$type[$i].'</option>
‘.”n”;
}
echo ‘ </select>[/code]

Any help or questions, please fire away.

Many thanks !

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJun 30.2006 — I haven't looked at your code in detail, but there's a good chance you can solve it yourself by adding some debug code:
<i>
</i>$result = mysql_query($query) [color=red]or die("Query failed: $query - " . mysql_error())[/color];
Copy linkTweet thisAlerts:
@invisionauthorJun 30.2006 — Thanks very much for your reply.

Unfortunately no error is printed. But it does change the values in the table to 'zero'. I think because it wants to insert text, but I want it to insert numbers.
Copy linkTweet thisAlerts:
@NogDogJul 01.2006 — You might want to try echo-ing the value of $query just to verify that all the variables which are you using have values.
Copy linkTweet thisAlerts:
@invisionauthorJul 01.2006 — Good call.

NogDog, you seem like a trustworthy person.

Could I possibly email you the 'edit_item.php' file and some SQL dumps of the tables used.

After thinking about it, I think I may have to store the index value('1','2','3') of the selected item, rather than the option value('footwear','clothing',etc.).

Thanks for any advice.
×

Success!

Help @invision spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...