karimali831 Posted April 19, 2010 Share Posted April 19, 2010 Ok hello, Be great if someone can correct this for me, I'll appreciate it. <?php $getid = safe_query("SELECT cupID from ".PREFIX."cup_matches"); while($dd = mysql_fetch_array($getid)) $id = $dd['cupID']; if(is1on1($id)) mysql_query("ALTER TABLE `".PREFIX."cup_matches` ADD `1on1` INT( 11 ) NOT NULL default '1' AFTER `einspruch`;") else mysql_query("ALTER TABLE `".PREFIX."cup_matches` ADD `1on1` INT( 11 ) NOT NULL default '0' AFTER `einspruch`;") OR die(PREFIX.'cup_matches <font color="red">failed!</font><br> You have already updated to V4.1.4b!<br />'); echo '<center><h2>Successfully updated to V4.1.4b!</h2><br><a href="index.php"><b>View Site</b></a></center>'; ?> Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted April 20, 2010 Share Posted April 20, 2010 I don't think you asked a question or told us what the problem is. <- Me trying to read your mind. Quote Link to comment Share on other sites More sharing options...
AndrewJ1313 Posted April 20, 2010 Share Posted April 20, 2010 Not sure what your question is or what kind of error you're getting, but for starters, in both query's, you're terminating before the closing quotes. mysql_query("ALTER TABLE `".PREFIX."cup_matches` ADD `1on1` INT( 11 ) NOT NULL default '1' AFTER `einspruch`;") else mysql_query("ALTER TABLE `".PREFIX."cup_matches` ADD `1on1` INT( 11 ) NOT NULL default '0' AFTER `einspruch`;") Should be: ...einspruch`" Also, "if" and "elseif" statements need curly brackets: if(something = true) { ...do somehing... } else { ...do this instead... } Hope that helps. Quote Link to comment Share on other sites More sharing options...
-Karl- Posted April 20, 2010 Share Posted April 20, 2010 Try this: <?php $getid = safe_query("SELECT cupID from ".PREFIX."cup_matches"); while($dd = mysql_fetch_array($getid)) $id = $dd['cupID']; if(is1on1($id)) { mysql_query("ALTER TABLE `".PREFIX."cup_matches` ADD `1on1` INT( 11 ) NOT NULL default '1' AFTER `einspruch`" } else { mysql_query("ALTER TABLE `".PREFIX."cup_matches` ADD `1on1` INT( 11 ) NOT NULL default '0' AFTER `einspruch`" } OR die(PREFIX.'cup_matches <font color="red">failed!</font><br> You have already updated to V4.1.4b!<br />'); echo '<center><h2>Successfully updated to V4.1.4b!</h2><br><a href="index.php"><b>View Site</b></a></center>'; ?> Quote Link to comment Share on other sites More sharing options...
havenpets Posted April 20, 2010 Share Posted April 20, 2010 <?php $getid = safe_query("SELECT cupID from ".PREFIX."cup_matches"); while($dd = mysql_fetch_array($getid)) $id = $dd['cupID']; if(is1on1($id)) { mysql_query("ALTER TABLE `".PREFIX."cup_matches` ADD `1on1` INT( 11 ) NOT NULL default '1' AFTER `einspruch`") ; } else { mysql_query("ALTER TABLE `".PREFIX."cup_matches` ADD `1on1` INT( 11 ) NOT NULL default '0' AFTER `einspruch`"); } OR die(PREFIX.'cup_matches <font color="red">failed!</font><br> You have already updated to V4.1.4b!<br />'); echo '<center><h2>Successfully updated to V4.1.4b!</h2><br><a href="index.php"><b>View Site</b></a></center>'; ?> Quote Link to comment Share on other sites More sharing options...
ignace Posted April 20, 2010 Share Posted April 20, 2010 Not sure what your question is or what kind of error you're getting, but for starters, in both query's, you're terminating before the closing quotes. mysql_query("ALTER TABLE `".PREFIX."cup_matches` ADD `1on1` INT( 11 ) NOT NULL default '1' AFTER `einspruch`;") else mysql_query("ALTER TABLE `".PREFIX."cup_matches` ADD `1on1` INT( 11 ) NOT NULL default '0' AFTER `einspruch`;") Should be: ...einspruch`" Nope. Because that would mean a syntax error mysql_query("ALTER TABLE `".PREFIX."cup_matches` ADD `1on1` INT( 11 ) NOT NULL default '0' AFTER `einspruch`" ?!? Also, "if" and "elseif" statements need curly brackets: They don't. But it's best to write 'em. Quote Link to comment Share on other sites More sharing options...
karimali831 Posted April 20, 2010 Author Share Posted April 20, 2010 havenpets and Karl, there is a problem with both scripts you posted. Syntax error I assume. I tried this: <?php $getid=safe_query("SELECT cupID FROM ".PREFIX."cup_matches"); $ds=mysql_fetch_array($getid); $cupID = $ds['cupID']; $ergebnis2=safe_query("SELECT 1on1 FROM ".PREFIX."cups WHERE ID='$cupID'"); $dl=mysql_fetch_array($ergebnis2); if($dl['1on1'] ==1) { mysql_query("ALTER TABLE `".PREFIX."cup_matches` ADD `1on1` INT( 11 ) NOT NULL default '1' AFTER `einspruch`;") OR die(PREFIX.'cup_matches <font color="red">failed!</font><br> You have already updated to V4.1.4b!<br />'); echo '<center><h2>Successfully updated to V4.1.4b!</h2><br><a href="index.php"><b>View Site</b></a></center>'; }else{ mysql_query("ALTER TABLE `".PREFIX."cup_matches` ADD `1on1` INT( 11 ) NOT NULL default '0' AFTER `einspruch`;") OR die(PREFIX.'cup_matches <font color="red">failed!</font><br> You have already updated to V4.1.4b!<br />'); echo '<center><h2>Successfully updated to V4.1.4b!</h2><br><a href="index.php"><b>View Site</b></a></center>'; } ?> No syntax error but adds "1" for each row. I'm trying to add a 1on1 column to my cup_matches table and insert value "1" if ID in the cups table has value "1" in the 1on1 column or insert value "0" if ID in the cups table has value "0" in the 1on1 column. Does that make sense? I believe the mysql_query must be changed? Changing ADD `1on1` INT( 11 ) NOT NULL default '0' AFTER `einspruch`;") to something like ADD `1on1` INT( 11 ) NOT NULL default '$dl['1on1']' AFTER `einspruch`;") make sense .. but won't work. Quote Link to comment Share on other sites More sharing options...
karimali831 Posted April 20, 2010 Author Share Posted April 20, 2010 my question does not make sense or is this rather complicated to do? Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted April 20, 2010 Share Posted April 20, 2010 Well what you wanted (by what you gave) has a syntax error. This should fix that.. ADD `1on1` INT( 11 ) NOT NULL default '".$dl['1on1']."' AFTER `einspruch`;") Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 20, 2010 Share Posted April 20, 2010 I'm trying to add a 1on1 column to my cup_matches table and insert value "1" if ID in the cups table has value "1" in the 1on1 column or insert value "0" if ID in the cups table has value "0" in the 1on1 column. Does that make sense? Not really. I believe the mysql_query must be changed? Irrelevant. my question does not make sense or is this rather complicated to do? The latter. Did I answer your questions? Those were the only questions I found. Did I miss any? Quote Link to comment Share on other sites More sharing options...
ignace Posted April 20, 2010 Share Posted April 20, 2010 my question does not make sense or is this rather complicated to do? Neither IMO your db just has a very bad design. Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted April 20, 2010 Share Posted April 20, 2010 Neither IMO your db just has a very bad design. You seem to say peoples db design is always bad? Quote Link to comment Share on other sites More sharing options...
ignace Posted April 20, 2010 Share Posted April 20, 2010 Neither IMO your db just has a very bad design. You seem to say peoples db design is always bad? Would you be posting any questions on these forums if you had a great application- and db design? Presumably not, as most projects people are working on have a medium difficulty but mostly pick an over-complicated solution probably due to a limited knowledge of the subject domain. Quote Link to comment Share on other sites More sharing options...
karimali831 Posted April 20, 2010 Author Share Posted April 20, 2010 Take a look at the attatchment, surely you will understand from that? I hope anyway. Not sure why you would say this database has a bad design.. why is this? If ID in the cups table, not cupID. [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
karimali831 Posted April 20, 2010 Author Share Posted April 20, 2010 (See post above and this is the current code:) <?php $getid=safe_query("SELECT cupID FROM ".PREFIX."cup_matches"); $ds=mysql_fetch_array($getid); $cupID = $ds['cupID']; $get1on1=safe_query("SELECT 1on1 FROM ".PREFIX."cups WHERE ID='$cupID'"); $dl=mysql_fetch_array($get1on1); mysql_query("ALTER TABLE `".PREFIX."cup_matches` ADD `1on1` INT( 11 ) NOT NULL default '".$dl['1on1']."' AFTER `einspruch`;") OR die(PREFIX.'cup_matches <font color="red">failed!</font><br> You have already updated to V4.1.4b!<br />'); echo '<center><h2>Successfully updated to V4.1.4b!</h2><br><a href="index.php"><b>View Site</b></a></center>'; ?> Problem: Adding incorrect value for added column at cup_matches table. (Adds 1 for all rows) Column "ID = 1" at _cups table -> 1on1 = 0 so it should add this column with 0 value if ID = 1 and cupID = 1. ID = cupID Quote Link to comment Share on other sites More sharing options...
karimali831 Posted April 20, 2010 Author Share Posted April 20, 2010 Was thinking if I need a WHERE clause for the mysql_query? Quote Link to comment Share on other sites More sharing options...
karimali831 Posted April 20, 2010 Author Share Posted April 20, 2010 no one? :'( Quote Link to comment Share on other sites More sharing options...
seventheyejosh Posted April 20, 2010 Share Posted April 20, 2010 You need to loop over each of your fetch_arrays() if there are more then one possible hits, and then use a WHERE. Or write an advanced query. Quote Link to comment Share on other sites More sharing options...
seventheyejosh Posted April 20, 2010 Share Posted April 20, 2010 Also +1 for: Neither IMO your db just has a very bad design. Seriously that is some terrible db action. Quote Link to comment Share on other sites More sharing options...
karimali831 Posted April 20, 2010 Author Share Posted April 20, 2010 You need to loop over each of your fetch_arrays() if there are more then one possible hits, and then use a WHERE. Or write an advanced query. That's what I thought but I have no idea how to do this... can you help me do this please using the existing code I posted previously? I'll appreciate it alot. Been stuck with this for the last few days... and haven't got very far Well this is German style, I have no idea what is good and what is bad.. but if it works, it works Quote Link to comment Share on other sites More sharing options...
seventheyejosh Posted April 20, 2010 Share Posted April 20, 2010 I don't believe database logic is bound to spoken-language constraints... And I'll see if I can make a loop up for you at some point, I'm busy at work now, someone else may wish to spearhead it Quote Link to comment Share on other sites More sharing options...
karimali831 Posted April 20, 2010 Author Share Posted April 20, 2010 You'll probably say this is terrible and laugh but I'm just trying different ways.. <?php $getid=safe_query("SELECT cupID FROM ".PREFIX."cup_matches"); $ds=mysql_fetch_array($getid); $cupID = $ds['cupID']; $ergebnis2=safe_query("SELECT 1on1 FROM ".PREFIX."cups WHERE ID='$cupID'"); $dl=mysql_fetch_array($ergebnis2); if(isset($_GET['action']) && $_GET['action'] == 'alter'){ safe_query("UPDATE ".PREFIX."cup_matches SET 1on1='".$dl['1on1']."' WHERE cupID='$cupID'"); echo '<center><h2>Successfully updated to V4.1.4b!</h2><br><a href="index.php"><b>View Site</b></a></center>'; }elseif(!$ds['1on1']) { mysql_query("ALTER TABLE `".PREFIX."cup_matches` ADD `1on1` INT( 11 ) NOT NULL default '1' AFTER `einspruch`;") OR die(PREFIX.'cup_matches <font color="red">failed!</font><br> You have already updated to V4.1.4b!<br />'); redirect('?site=update&action=alter', '<center>Now sorting rows</center>', 0); } ?> Quote Link to comment Share on other sites More sharing options...
karimali831 Posted April 20, 2010 Author Share Posted April 20, 2010 pleease anyone? :-\ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.