Jump to content

digitalgod

Members
  • Posts

    374
  • Joined

  • Last visited

    Never

Everything posted by digitalgod

  1. anyone?  I keep trying a lot of different things but I fear that my eyes are too tired and I'm getting lost in my own code
  2. hey guys, what I'm basicly trying to do is populating a table with elements from one table and at the same time selecting the element that's in another table... don't know if that made sense but here's what I mean [code] <?php $result=mysql_query("SELECT * FROM events WHERE name='". $name ."'") or die(query_error()); $row=mysql_fetch_array($result); $query=mysql_query("SELECT * FROM djs") or die(query_error()); $data=mysql_fetch_array($query); $aDj = array(); //putting in the array all of the names of the djs in the djs table while ($data2 = mysql_fetch_array($query)) { array_push($aDj,$data2['name']); } ?> <select name="dj" id="dj">           <option>Choose one</option>           <?php //populating the drop down with that array but selecting the dj that is in the table events foreach ($aDj as $val) {     echo "<option value='$val'";       if ($val==$data['name']) { echo " selected"; }       echo ">".$val;       } ?>         </select> [/code] right now I have 2 names but for some reason it's only displaying the one that isn't in the events, can't figure out why.
  3. hey ken, here's the code I'm currently using, it kind of works when you first decide on the order but if you go back and change the order it won't work anymore. Here's what I got [code] <?php //echo '<pre>' . print_r($_POST,true) . '</pre>'; $NAList = implode ("','", $_POST['NA']); $DAList = implode ("','", $_POST['DA']); $type = $_POST['type']; $dj = $_POST['dj']; foreach($_POST['order'] as $k => $val) { echo $_POST['NA'][$val] . '<br>'; echo $k; mysql_query("UPDATE " . $prefix . "news SET orderList='".$k."' WHERE headline='".$_POST['NA'][$val]."'") or die(query_error()); } $_SESSION['add_result']=mysql_query("SELECT * FROM ".$prefix."news WHERE headline IN('$NAList') ORDER by orderList") or die(query_error()); ?> [/code] and in the newsletter_preview.php I got [code] <?php $result = $_SESSION['add_result']; while ($row=mysql_fetch_array($result)) { //display the articles in html } ?> [/code]
  4. nevermind my bad, had a 'name' too many in there thanks!
  5. I tried that but it gave me an error.... the columns of both tables match but I just need to check the names
  6. I'm trying to display everything in 1 table that's not in another table. [code] <?php $sql='SELECT * FROM djs WHERE name NOT ?> [/code] I need to select all the djs from the djs table that are not in the djsweek table... how can I do that?
  7. ok tried doing this but no matter what I do the values are always 1 and 0 in that order for $val [code] <?php foreach($_POST['order'] as $k => $val) { echo $_POST['NA'][$val] . '<br>'; echo $val; mysql_query("UPDATE " . $prefix . "news SET orderList='".$val."' WHERE headline='".$_POST['NA'][$val]."'") or die(query_error()); } ?> [/code] also is there a way to only process the fields that got checked, say I have 20 articles and I only check 5 of them and give those 5 an order, I don't want to process the order of the other fields
  8. ok how about adding an extra row in the db for the order but how can I UPDATE the db using your code [code] foreach($_POST['order'] as $k => $val) {     echo $_POST['NA'][$val] . '<br>'; } [/code] that way I can query the db and just sort it with the order row [code] mysql_query("SELECT * FROM ".$prefix."news WHERE headline IN('$NAList') ORDER by orderList") or die(query_error()); [/code]
  9. this is harder than I expected... I don't think I can use it that way because I display the articles in another page with SESSIONS, this is what I did before [code] $NAList = implode ("','", $_POST['NA']); $result=mysql_query("SELECT * FROM ".$prefix."news WHERE headline IN('$NAList')") or die(query_error()); $_SESSION['add_result'] = $result; $tmpl->add_template("newsletter_preview"); [/code] and in newsletter_preview I have [code] while ($row=mysql_fetch_array($_SESSION['add_result'])) { // display articles } [/code]
  10. thanks Ken that works well but the reason why I did like that was so that I can query it after like so $result=mysql_query("SELECT * FROM ".$prefix."news WHERE headline IN('$NAList')") or die(query_error()); how can I query the db with your way?
  11. this is what I get with that line of code [code]Array (     [process] => yes     [size_limit] => 500     [NA] => Array         (             [0] => test             [1] => test2         )     [order] => Array         (             [0] => 0             [1] => 1         )     [type] => Choose one     [send] => Preview )[/code] and I changed my code to this [code] echo '<pre>' . print_r($_POST,true) . '</pre>'; $NAList = implode ("','", $_POST['NA']); $orderList = array(); foreach($_POST['order'] as $k => $val) { $orderList[] = $val; } foreach($orderList as $v) { echo $NAList[$v] . "<br>"; } [/code] and the echo gives me t e
  12. that didn't work, I get Notice: Array to string conversion on line 191    which is the explode and the only thing that gets echoed is a t.... don't know where that's coming from
  13. for some reason I keep getting this error Warning: Invalid argument supplied for foreach() [code] $NAList = implode ("','", $_POST['NA']); $orderList = implode ("','", $_POST['order']); foreach($orderList as $val) { echo $NAList[$val] . "<br>"; } [/code] and this is my new form [code] for($i=1;$i<=$num_rows;$i++) { $new_i = $i--; $select_drop .= '<option value="' . $new_i . '">' . $i . '</option>'; } <table width ="80%"><? if ($num_rows < 1) { echo 'There are no new News'; } else { for ($i=0;$i<$num_rows;$i++) { $ID = mysql_result($result,$i,"headline"); $NA= mysql_result($result,$i,"headline"); echo '<tr><td>'.$ID.'</td><td width="100%"><div align="left"><input type ="checkbox" name="NA[]" value="'.$ID.'"><select name="order[]">'.$select_drop.'</select></div></td></tr>'; } }?> </table> [/code] is there a reason why I keep getting this error?
  14. you got me there :P But it's in an admin panel and only one user will have access to it...
  15. for that I can usually javascript so that the form is checked before it gets processed. thanks guys for your help.
  16. problem with the radio button is that I don't know in advance how many news articles are in the database, so if there are 20 of them the page won't look very nice if every single headline has 20 radio buttons next to it...
  17. so I should add a dropdown that displays from 1 to how many news item are being showed so that the user can select what order he wants? and if I do that how do I resort the array or is there a way that they can be placed in the array in the correct order when it gets processed?
  18. well here's what my form looks like [code] <td width="151">Select News :</td>        <td width="442"><? if ($num_rows < 1) { echo 'There are no new News'; } else { for ($i=0;$i<$num_rows;$i++) { $ID = mysql_result($result,$i,"headline"); $NA= mysql_result($result,$i,"headline"); echo '<input type ="checkbox" name="NA[]" value="'.$ID.'"> '.$ID.''; } }?></td> [/code] and here's how it gets processed [code] $NAList = implode ("','", $_POST['NA']); [/code] [quote author=emehrkay link=topic=100095.msg394643#msg394643 date=1152560093] you could put the results in an array then parse the array based on the predefined order [/quote] that's what I'm trying to do, getting the order
  19. hey guys, I'm kind of stumped, I'm trying to display the results of a query in a custom order, here's an example of what I mean. for instance you have News 1 News 2 News 3 News 4 News 5 (those headlines are fetched from the db) and I choose the headlines via checkboxes in this order News 4 News 2 News 3 News 5 News 1 when I submit the form how can I have them display in that order?
  20. so is there a way to actually get each content row seperatly and not all joined together because when I do [code] <? while ($row=mysql_fetch_array($result)) { echo $row['content']; } ?> [/code] It outputs everything together...
  21. thanks Barand that worked perfectly. Do you know how I can retrieve the info for each row seperatly? right now if I echo $row['content'] I get blablabblablab3  (test1 and test3 combined together) but I want to be able to echo the headline and content of each news seperatly
  22. no one? ok I'll simplify things, I need to query a table depending on what a user checks so let's say I have this in my table +----------------------------------------+ | id | headline | content | date                | +----------------------------------------+ | 1 | test1 | blablab | 2006-07-09            | +----------------------------------------+ | 2 | test2 | blablab2 | 2006-07-09          | +----------------------------------------+ | 3 | test3 | blablab3 | 2006-07-09          | +----------------------------------------+ and in the form the user checks test1 and test3 when the form is processed everything that got checked goes in an array like so [code] $qtmp = array(); foreach($_POST['NA'] as $k => $v) {     $qtmp[] = $v; } [/code] now I want to query the databse so that it displays the data of everything in test1 and test3,  Itried doing this but it just gives me an error [code] $result=mysql_query("SELECT * FROM ".$prefix."news WHERE headline IN('. implode(',', $qtmp). '") or die(query_error()); while ($row=mysql_fetch_array($result)) { echo $row['content']; } [/code] what am I doing wrong??
  23. Hey guys, I have checkboxes that are generated with elements from the db and I'd like it when the user clicks on submit it stores whatever he checked into a session so it can be used on another page. here's what I got in my form [code] <?php $pf_time = strtotime("-21 days"); $pf_date = date("Y-m-d", $pf_time); $result=mysql_query("SELECT * FROM news WHERE date >= " . $pf_date . " ORDER by id") or die(query_error()); $row=mysql_fetch_array($result); $num_rows = mysql_num_rows($result); $result2=mysql_query("SELECT * FROM events") or die(query_error()); $row2=mysql_fetch_array($result2); $num_rows2 = mysql_num_rows($result2); ?> <div id="article"> <form action="admin.php?a=newnewsletter" method="post" enctype="multipart/form-data" name="form" id="form"> <input type="hidden" name="process" value="yes" /> <input type="hidden" name="size_limit" value="500" />     <input name="size_limit" type="hidden" id="size_limit" value="500" />     <table width="603" border="0">       <tr>         <td colspan="2">&nbsp;</td>       </tr>       <tr>         <td width="151">Select News :</td>         <td width="442"><? if ($num_rows < 1) { echo 'There are no new News'; } else { for ($i=0;$i<$num_rows;$i++) { $ID = mysql_result($result,$i,"headline"); $NA= mysql_result($result,$i,"headline"); echo '<input type ="checkbox" name="NA[]" value="'.$ID.'"> '.$ID.''; } }?></td>       </tr>       <tr>         <td>Select Events:</td>         <td><? if ($num_rows < 1) { echo 'There are no new News'; } else { for ($i=0;$i<$num_rows2;$i++) { $ID2 = mysql_result($result2,$i,"name"); $DA= mysql_result($result2,$i,"name"); echo '<input type ="checkbox" name="DA[]" value="'.$ID2.'"> '.$ID2.''; } }?></td>       </tr>             <tr>         <td>Type:</td>         <td><select name="type" id="type">           <option>Choose one</option>           <option value="house">House</option>           <option value="hip hop">Hip Hop</option>           <option value="both">Both</option>         </select>         </td>       </tr>           </table> <input name="send" type="submit" id="send" value="Submit"/> </form> </div> [/code] I want all that info to be stored in a session, here's what I got so far in admin.php [code] $process = $_POST['process'];       if ($process == "yes") {           $qtmp = array();           $wtmp = array();           foreach($_POST['NA'] as $k => $v) {           $qtmp[] = $v;           }            foreach($_POST['DA'] as $c => $b) {            $wtmp[] = $b; } //... [/code] that grabs everything that's been checked but how can I reuse that on another page, let's say someone checks news 1, news 2, news 6 I'd like to take that info, query the news table and get all the info for each of those headlines... how can I do this?
  24. hey guys, I was wondering how can I display something from a database from a certain date till now.
×
×
  • 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.