Jump to content

mattennant

Members
  • Posts

    42
  • Joined

  • Last visited

    Never

Everything posted by mattennant

  1. does this help //send an email here? $body = "Hi\n email body here\n .\n website: http://www.site.com.com Username: {$_POST['username']}\n Password: {$_POST['password']}\n "; mail($_POST['email'], 'subject line here' , $body, 'From: youremail@domain.com');
  2. hello have followed darkwaters advice and now have three tables articles - contains article_id - headline- description etc keywords - keyword_id - backpain - fitness training etc keyword_rank keywordrank_id - keyword_id - article_id - rank everytime a new article is added the user s/he checks a checkbox if that keyword is relevent eg []backpain []fitness training etc etc these checked items are stored as rank in the keyword_rank (at the moment as a 1) by query is how best to get the related article to run alongside the article at the moment i have the following (keyword_id 4 is fitness training) SELECT * FROM keyword_rank LEFT JOIN articles ON articles.article_id = keyword_rank. article_id WHERE keyword_id = 4 ORDER by keyword_rank.rank DESC this is fine to relate one keyword, but when two or more are checked i run into problems, i've thought about putting the statement in a loop corresponding to the number of keywords selected, but this would result in the same row getting selected more than once, thinking that there must be a much slicker solution,
  3. Thanks darkwater, thought that might well be the case. Is there though a solution to solve this problem, in a kinda unproper manner,before i head down the normalised route, or am i just making more work for myself?? thaks for your time Mat
  4. Hi There I'm trying for the first time to relate articles across a site i am building the idea is that everytime say for example a news item is added in the cms, the admin will check 'check boxes' of the categories that story falls into [] backpain [] fitness training [] alternative therapy etc etc at the moment i am storing the array as a comma seperated array in a column called keywords (i realise there could be issues here) so far all well and good i retrieve the data as fllows do { $nkw = explode(',',$row_news['keywords']); if (($row_news['article_id']) ==(in_array($row_article['keywords'], $nkw))){ echo '<li><a href="mat_news.php?article_id=' . $row_news['article_id'] . '" target="_self" title="'.$row_news['headline'] .'">' . $row_news['headline'] . '</a></li>'; } } while ($row_news = mysql_fetch_assoc($news2)); this works fine if there is an exact match from the checked checkboxes, but i want to relate the articles even if there is just a single match from one of the checkboxes, i'm sure this must be simple, but i've been toying with this for ages any help much appreciated mat
  5. bingo that's the devil thanks a bunch for your help mat
  6. I'm trying to sort out sending an email to admin when a user updates their info all is going fine with the following if ($_POST['mailer'] =='y'){ $body = 'you have a new message from a user.' ; mail($_POST['email'], 'Message from user' , $body, 'blah@blah.com'); but if i try if ($_POST['mailer'] =='y'){ $body = 'you have a new message from a user.' ; $from = 'blah@blah.com' ; mail($_POST['email'], 'Message from user' , $body, $from); i receive the mail, but it comes from Apache rather than blah@blah.com do i need to looka t my server setting, or am i making some stupid error Thanks Mat
  7. that worked a treat, thanks so much
  8. Hi there I'm trying to display the results of a user table (userdetails) who have not been assigned a particular task in a task table (display_tasks) and to be honest i'm struggling a bit. i can select the users from the task table who have been assigned the task like this a) SELECT FROM userdetails LEFT JOIN display_tasks ON display_tasks.user_id = userdetails.number WHERE display_tasks.task_ref = '170' //170 is the task reference i will get this in from the url but if i try and select the opposite i get all the users who have been assigned other tasks b) SELECT FROM userdetails LEFT JOIN display_tasks ON display_tasks.user_id = userdetails.number WHERE display_tasks.task_ref != '170' //170 is the task reference i will get this in from the url Is there a simple way to do this, put simply terms i want to select all the users from the user table unless they have already been assigned that particular task. Thanks
  9. found it if anyone is interested mysql_insert_id is the answer http://uk.php.net/mysql_insert_id
  10. not sure but is it the spelling of contact if (!isset ($_POST['cantactform'])){
  11. Hi There I want to insert data from one form into two different tables with one form submit, i want the primary key from 'question' table (main_id) to be the foreign key in the 'question_intro' Is there a way to do this? The only way can think is to get the latest primary key from the 'question' table in a hidden field add 1 to it and insert that number as the foreign key, but that all feels a bit clumsy. here's my code // this tables auto incrementing primary key is called main_id if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO question (task_ref, step_ref, step_type) VALUES (%s, %s, %s)", GetSQLValueString($_POST['task_ref'], "int"), GetSQLValueString($_POST['step_ref'], "int"), GetSQLValueString($_POST['step_type'], "int")); mysql_select_db($database_mattyboy, $mattyboy); $Result1 = mysql_query($insertSQL, $mattyboy) or die(mysql_error()); // iwant to pass the primary key from the above table to this table as the foreign key $insertSQL2 = sprintf("INSERT INTO question_intro (main_id, task_ref, question) VALUES (%s, %s, %s)", GetSQLValueString($_POST['main_id'], "int"),// maybe get this from a hidden field GetSQLValueString($_POST['task_ref'], "int"), GetSQLValueString($_POST['question'], "text")); mysql_select_db($database_mattyboy, $mattyboy); $Result2 = mysql_query($insertSQL2, $mattyboy) or die(mysql_error()); Thanks
  12. does this look right to you, getting a mysql error select question_text.question1, answer_text.answer1 from question_text left joint answer_text.foreign on question_text question_text.number=answer_text.foreign FROM question_text WHERE task_ref = 'colname' AND step_ref = 'colname2'
  13. i'm just looking into that join query now, thanks for that, will hopefully get this sorted before my eyelids finally shut, thanks for the advice
  14. i do have a question id it's called, step_ref, i think i missed that bit out -oops ,i'm having no trouble matching up the q and a's just spitting out all the answers - could be a late night!
  15. the query is a bit embarrassing, it's spewed out from dreamweaver, but here goes, here's the answer query $colname2_task_answer = "-1"; if (isset($_GET['step_ref'])) { $colname2_task_answer = (get_magic_quotes_gpc()) ? $_GET['step_ref'] : addslashes($_GET['step_ref']); } $colname_task_answer = "-1"; if (isset($_GET['task_ref'])) { $colname_task_answer = (get_magic_quotes_gpc()) ? $_GET['task_ref'] : addslashes($_GET['task_ref']); } mysql_select_db($database_mattyboy, $mattyboy); $query_task_answer = sprintf("SELECT * FROM answer_text WHERE task_ref = %s AND step_ref = %s", $colname_task_answer,$colname2_task_answer); $task_answer = mysql_query($query_task_answer, $mattyboy) or die(mysql_error()); $row_task_answer = mysql_fetch_assoc($task_answer); $totalRows_task_answer = mysql_num_rows($task_answer); and here's the here's the question query $colname2_task_question = "-1"; if (isset($_GET['step_ref'])) { $colname2_task_question = (get_magic_quotes_gpc()) ? $_GET['step_ref'] : addslashes($_GET['step_ref']); } $colname_task_question = "-1"; if (isset($_GET['task_ref'])) { $colname_task_question = (get_magic_quotes_gpc()) ? $_GET['task_ref'] : addslashes($_GET['task_ref']); } mysql_select_db($database_mattyboy, $mattyboy); $query_task_question = sprintf("SELECT * FROM question_text WHERE task_ref = '%s' AND step_ref = '%s'", $colname_task_question,$colname2_task_question); $task_question = mysql_query($query_task_question, $mattyboy) or die(mysql_error()); $row_task_question = mysql_fetch_assoc($task_question); $totalRows_task_question = mysql_num_rows($task_question); I Know
  16. I have two tables one contains a row of questions, the other contains users answers to those questions. question table rows are roughly like this id - question1 - question2 - question3 - etc etc answer table is id - username - answer1 - answer2 - answer3 - etc etc i'm trying to display the results as follows question 1 answer user 1 answer user 2 question 2 answer user 1 answer user 2 the following code gets me this far question 1 answer user 1 answer user 2 question 2 but i am unable to display the answers after question 1 - hers's the code $number = $row_task_question['qnum']; for( $y=1; $y<=$number; $y++ ){ print "\t\n"; print "\t\t<strong>"; echo $row_task_question['question'.($y)] . '</strong><p>'; do { echo $row_task_answer['answer'.($y)] . '<br>'; echo $row_task_answer['username'].'<P></td>'; } while ($row_task_answer = mysql_fetch_assoc($task_answer)); print "\n"; } i'm hoping i'm missing something simple and obvious, but it's driving me crazy, any help or pointers in the right direction would be much appreciated thanks mat
  17. hi this is now solved in case anyone is interested here is the solution <?php $i = 0; while($rows=mysql_fetch_array($result)){ ?> ...... <tr> <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $i++;?>" /></td> Then for the insert loop: foreach($_POST['checkbox'] as $i) { $sql1="INSERT INTO $tbl_name2 (name, lastname, email)VALUES('{$_POST['name'][$i]}', '{$_POST['lastname'][$i]}', '{$_POST['email'][$i]}')"; cool
  18. Hi there. I'm looking to select using checkboxes certain rows from the results of 'table a' and add the selected rows to another table using checkboxes. I Have had limited success adapting some code for deleting multiple records using checkboxes. But to be honest got a bit stuck At the moment i check one check box one row is added, but not the one i checked Here's what i have so far <?php $tbl_name="test_mysql"; // Table name $tbl_name2="test_mysql2"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); // Count table rows $count=mysql_num_rows($result); ?> ........... <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="y" /></td> <td align="center"><input name="name[]" type="text" id="name" value="<? echo $rows['name']; ?>"></td> <td align="center"><input name="lastname[]" type="text" id="lastname" value="<? echo $rows['lastname']; ?>"></td> <td align="center"><input name="email[]" type="text" id="email" value="<? echo $rows['email']; ?>"></td> </tr> <?php } ?> <tr> <td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td> .......... <?php // Get values from form $name=$_POST['name']; $lastname=$_POST['lastname']; $email=$_POST['email']; // Check if button name "Submit" is active, do this if($checkbox){ for($i=0;$i<$count;$i++){ if($checkbox[$i] == 'y'){ $sql1="INSERT INTO $tbl_name2 (name, lastname, email)VALUES('$name[$i]', '$lastname[$i]', '$email[$i]')"; $result1=mysql_query($sql1); } } } if($result1){ header("location:insert_multiple.php"); } mysql_close(); ?> i realise i somehow have to get the selected checkboxes into the loop, but have drawn a bit of a blank. Any help much appreciated Mat
  19. hello there i'm trying to load a bunch of images from my database into the cache, using php and javascript. so really im trying to recreate the following bit of code, using a repeat loop. [code]<body onload="MM_preloadImages('images/uploads/ballettiff.jpg');MM_preloadImages('images/uploads/blue_silk_liberty_t047.jpg');MM_preloadImages('images/uploads/brown_spot_blouse_021.jpg')">[/code] the attempt that isn't working looks like this [code]<body onload="<?php do { ?> <?php echo "MM_preloadImages('"; ?>         <?php echo $row_all_images['image']; ?> <?php echo "');"; ?>         <?php } while ($row_all_images = mysql_fetch_assoc($all_images)); ?>">[/code] now i'm guessing i need to escape some characters or something, but i'm at a bit of a loss. any help much appreciated. mat
  20. that's the one - thanks so much, i can go to sleep happy now
  21. Hello there i've been struggling with this for a while now and wonder if anyone out there can help me out. I'm trying to create an m3u file to stream music in a kind of radio player. I want the list of mp3's to come from my database music uploads. I've managed to generate the m3u file when manually entering the mp3 paths within a php file see code below [code]<? header("Content-Type: audio/mpegurl"); header("Content-Disposition: attachment; filename=playlist.m3u"); print "http://www.myurl.co.uk/nowax/uploads/track1.mp3\r\n"; print "http://www.myurl.co.uk/nowax/uploads/track2.mp3\r\n"; ?>[/code] on the back of this sucess i tried to populate the mp3 paths from the relevent row in the database (see below) [code]<?php require_once('../../connections_handcode/handcode.php'); ?> <?php header("Content-Type: audio/mpegurl"); header("Content-Disposition: attachment; filename=playlist.m3u"); $query = "SELECT track_upload  FROM music_uploads"; $result = @mysql_query ($query); if  ($result){ while ($row = mysql_fetch_array($result, MYSQL_NUM)){ echo'http://www.myurl.co.uk$row[0]'."\n"; } }else{ echo'error'; } ?>[/code] I believe, although i'm not certain that the above code, does not put each mp3 on a seperate line as i need to for the generated m3u file. I hope this is something simple thanks in anticipation matthew
  22. I'm trying to prduce an events calendar similaar to the one here [url=http://fat-cat.co.uk/fatcat/events.php]http://fat-cat.co.uk/fatcat/events.php[/url] I think i need to run a query to produce a unique month from my table, and within that loop run a second query for the days. I've successfully got the first loop running, it's the second i'm struggling with. is there a simple answer to this problem. here's the code [code]<?php $query= "SELECT distinct DATE_FORMAT(date,'%M  %Y') AS dr FROM hoarse_events ORDER BY date ASC"; $result = mysql_query ($query); $query2= "SELECT  DATE_FORMAT(date,'%M %d %Y') AS dr FROM hoarse_events ORDER BY date ASC"; $result2 = mysql_query ($query2);     if($result){ echo'<table align="left" cellspacing="" cellpadding""> '; //fetchand print all results while ($row = mysql_fetch_array($result, MYSQL_NUM)){ echo"<tr><td align=\"left\"> $row[0]</td><td align=\"left\"> $row[2]</td></tr>\n"; } echo '</table>'; mysql_free_result ($result);//free up resources }else{//if it did not run ok echo'<p> something is wrong.</p><p>' . mysql_error().'</P>'; } ?> [/code] I've tried sticking the second loop within the first, but i'm getting nothing but errors, any help much appreciated
  23. hello there i'm trying to achieve that ...[read more] type of thing i've got a little bit of code that limits the length of a string from a column of my database. It works fine unless the string length is less than the limit i have assigned. in that instance nothing is displayed. I'm sure it must be a simple thing i'm missing, but i'm struggling the code i'm using goes like this [code]<? $var = $row_projects['description']; $varlength = strlen($var); $limit = 300; if ($varlength > $limit) { $var = substr($var,0,$limit); echo $var; } ?>[/code] any help appreciated mat
  24. that makes sense, but for some reason it's still not working, i can't think of any reason why it shouldn't though. Thanks for having a look.
×
×
  • 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.