Jump to content

dinita

Members
  • Posts

    24
  • Joined

  • Last visited

About dinita

  • Birthday 12/23/1987

Profile Information

  • Gender
    Female
  • Location
    London

dinita's Achievements

Member

Member (2/5)

1

Reputation

  1. I'm a big fan of Big Brother UK and as a fun project I have built a Twitter hash tag counter to count the battle between the contestants this year. Using the API from Topsy.com I have built a counter that shows the amount of tweets daily, monthly and hourly. However, I wondered if it was possible for me to calculate the amount of tweets say between the time the page was loaded and the time a user clicks stop so I can see how the numbers have change during the show. Would it be possible to use the setTimeOut() function or is there a better way of doing this? heres my code: <?php error_reporting(0); $jsonurl = "http://otter.topsy.com/searchcount.json?q=%23teamrylan&type=tweet&apikey=FJWCK5YSZIBEUZX4HYJQAAAAABLTPFQ3DVIQAAAAAAAFQGYA"; $json = file_get_contents($jsonurl, 0, null, null); $json_output = json_decode($json, true); $json_output = array_values($json_output); foreach ($json_output as $key => $val) { $hourly = number_format($val["h"]); $daily = number_format($val["d"]); $weekly = number_format($val["w"]); $monthly = number_format($val["m"]); $alltime = number_format($val["a"]); } echo '<strong>How many times have people tweeted #TeamRylan</strong><br /><br />'; echo 'In the last Hour: ' . $hourly . '<br />'; echo 'In the last Day: ' . $daily . '<br />'; echo 'In the last Week: ' . $weekly . '<br />'; echo 'In the last Month: ' . $monthly . '<br />'; echo 'Ever: ' . $alltime . '<br />'; ?>
  2. My code is below, but in short I created arrays to represent each of the dynamic text fields in my Flash project. Its probably not the smartest way to do this but I'm just a beginner. <?php error_reporting(-1); session_name("name"); session_start(); //functions function redirect_page($url) { if(!headers_sent()) { header("Location: ".$url); exit; } else { echo '<script type="text/javascript">'; echo 'window.location.href="'.$url.'";'; echo '</script>'; echo '<noscript>'; echo '<meta http-equiv="refresh" content="0;url='.$url.'" />'; echo '</noscript>'; exit; } } function getquestions($id) { $sql =mysql_query("select text FROM questions WHERE quiz_ID =$id "); $questions = array(); while($row = mysql_fetch_row($sql)) { $questions[] = $row[0]; } return $questions; } function getquesid($id) { $sql =mysql_query("select ID FROM questions WHERE quiz_ID =$id "); $questions = array(); while($row = mysql_fetch_row($sql)) { $questions[] = $row[0]; } return $questions; } function getanswers() { foreach ($quesid as $id) { $sql = mysql_query("select answer FROM answers WHERE question_ID= $id "); } $answers = array(); while($row =mysql_fetch_row($sql)) { $answers[] = $row[0]; } return $answers; } function getcorrect($id) { $sql = mysql_query("SELECT correct FROM answers WHERE question_ID= $id "); $correct =array(); while($row =mysql_fetch_assoc($sql)) { $correct[] =$row["correct"]; } return $correct; } //Connect to Database $con = mysql_connect(); if(!$con) { die('Could not connect: '.mysql_error()); } else { // SELECT DATABASE mysql_select_db("quizCreation", $con); } //GET NAME if(isset($_SESSION['quizid'])) { $id =$_SESSION['quizid']; } else { $id = 6; } //get quiz name $sql = mysql_query("SELECT Name FROM quizName WHERE ID= '$id'"); while ($row = mysql_fetch_array($sql)) { $name = $row['Name']; } //use quiz id to output array of question ID's and text $question = implode ("/",getquestions($id)); $quesid =getquesid($id); $answers = array(); // use question ID's to output 4 arrays foreach ($quesid as $id) { $sql = mysql_query("select answer FROM answers WHERE question_ID= $id "); while($row =mysql_fetch_row($sql)) { $answers[] = $row[0]; } } $one = array( $answers[0],$answers[4],$answers[8],$answers[12],$answers[16],$answers[20],$answers[24],$answers[28]); $two = array( $answers[1],$answers[5],$answers[9],$answers[13],$answers[17],$answers[21],$answers[25],$answers[29]); $three =array( $answers[2],$answers[6],$answers[10],$answers[14],$answers[18],$answers[22],$answers[26],$answers[30]); $four =array( $answers[3],$answers[7],$answers[11],$answers[15],$answers[19],$answers[23],$answers[27],$answers[31]); $answerone = implode ("/",$one); $answertwo = implode ("/", $two); $answerthree = implode ("/", $three); $answerfour =implode ("/", $four); // use question ID's to output array of correct answers $cor = array(); foreach ($quesid as $id) { $sql = mysql_query("select correct FROM answers WHERE question_ID= $id "); while($row =mysql_fetch_row($sql)) { $cor[] = $row[0]; } } $cor1 =array ($cor[0],$cor[4],$cor[8],$cor[12],$cor[16],$cor[20],$cor[24],$cor[28]); $cor2 =array ($cor[1],$cor[5],$cor[9],$cor[13],$cor[17],$cor[21],$cor[25],$cor[29]); $cor3 =array ($cor[2],$cor[6],$cor[10],$cor[14],$cor[18],$cor[22],$cor[26],$cor[30]); $cor4 =array ($cor[3],$cor[7],$cor[11],$cor[15],$cor[19],$cor[23],$cor[27],$cor[31]); $correctone = implode ("/", $cor1); $correcttwo = implode ("/", $cor2); $correctthree = implode("/", $cor3); $correctfour = implode("/", $cor4); //echo this information echo "name=". urlencode($name); echo "&questions=" . urlencode($question); echo "&answerone=". urlencode($answerone); echo "&answertwo=". urlencode($answertwo); echo "&answerthree=". urlencode($answerthree); echo "&answerfour=". urlencode($answerfour); echo "&correctone=".urlencode($correctone); echo "&correcttwo=".urlencode($correcttwo); echo "&correctthree=".urlencode($correctthree); echo "&correctfour=".urlencode($correctfour); mysql_close($con);
  3. Hi Neil, thanks for getting back to me I tried this and after clicking the link back to the home page via another php file which just prints the username and then redirects to the home page using the HTTP Header Response, this gives me an undefined variable error.
  4. I have a question about passing a variable from php to html and back again Ideally i'd like to pass a customers name inputted into php file using a form out into the form submission page as a hidden form input and then use this value in a new php file when a button is pressed to send them back to the home page. the aim is to show the users name once they have completed the form. I've had a look around and many people suggest using code similar to this: value="<?php echo htmlspecialchars($name); ?>" but if i include this in my html form do I not have to save the html document as php? I hope someone can help, thanks in advance!
  5. Please excuse my terrible ability to explain what I'm trying to do, my aim is to draw questions and answers from a database to be output in flash. My problem is: I have created an array listing all of the question ids for a particular quiz, I would like to create another array that lists all the enteries in the database that have those id's so far I have managed to create an array which shows the last ID's answers. what i want is to create 8 seperate arrays not just one? foreach ($quesid as $id) { $sql = mysql_query("select answer FROM answers WHERE question_ID= $id "); $answers = array(); while($row =mysql_fetch_row($sql)) { $answers[] = $row[0]; } } print_r ($answers); echo "questions=" . $question."&"; print_r ($quesid); here is what is output: Array ( [0] => Bulgaria [1] => Nicaragua [2] => Albania [3] => Romania ) questions=The ‘Sea Swallow’ is an alternative name for which bird?/In which sport would you see a ‘Western Roll’?/Who is better known as ‘Herbert Khaury’?/'Diet' is the parliament of which country?/What is the real first name of Coco Chanel?/'The Aztecs' were natives of which country?/What was invented by‘O.A. North’ in 1869?/King Zog was the ruler of which country?&Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 ) the first array is what i need but i need it 7 other times.
  6. I'm trying to make it so that my code takes an id given at the beginning and uses this to return a set of arrays. Can anyone explain why my code might work (meaning echo the desired arrays ) like this: 1Array ( [0] => The ‘Sea Swallow’ is an alternative name for which bird? [1] => In which sport would you see a ‘Western Roll’? [2] => Who is better known as ‘Herbert Khaury’? [3] => 'Diet' is the parliament of which country? [4] => What is the real first name of Coco Chanel? [5] => 'The Aztecs' were natives of which country? [6] => What was invented by‘O.A. North’ in 1869? [7] => King Zog was the ruler of which country? ) Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 ) when I echo the variable id and not when I use the return function? when the return function is used I recieve no errors but nothing is printed either. Ideally I'd like the id variable to be returned as I don't really want to see it echoed. I know its probably something really simple but I just can't work it out, any help would be much appreciated, code below: <?php error_reporting(-1); function getquestions($id) { $sql =mysql_query("select text FROM questions WHERE quiz_ID =$id "); $questions = array(); while($row = mysql_fetch_row($sql)) { $questions[] = $row[0]; } return $questions; } function getquesid($id) { $sql =mysql_query("select ID FROM questions WHERE quiz_ID =$id "); $questions = array(); while($row = mysql_fetch_row($sql)) { $questions[] = $row[0]; } return $questions; } //Connect to Database $con = mysql_connect("localhost","dinita", "3nd3m0luk"); if(!$con) { die('Could not connect: '.mysql_error()); } else { // SELECT DATABASE mysql_select_db("quizCreation", $con); } //GET NAME $name ="my quiz"; //get quiz id $sql = mysql_query("SELECT ID FROM quizName WHERE Name= '$name'"); while ($row = mysql_fetch_array($sql)) { $id = $row['ID']; } echo $id; $quizid =$id; $question = getquestions($quizid); $quesid =getquesid($quizid); print_r ($question); print_r($quesid); //use quiz id to output array of question ID's and text // use question ID's to output 4 arrays mysql_close($con);
  7. 2 weeks into learning PHP and I wonder why its taken me so long to get round to learning it!

  8. your right I was doing it wrong! I thought I needed the array to split into separate variables so the Actionscript could read these and display them into separate boxes by calling each variable. Instead I've used the array to echo a string split using backslashes and removed the backslashes in the Actionscript using the split function and then turned that string into an array. Thanks for being so patient with me!
  9. quick question really.. trying to call an extract function where the keys of the array are numbers? a variable cannot start with a number, so how would I call my new variables?
  10. Thank you, Dan and everyone else for your input!
  11. thanks for all your help, but changing the numbers from strings to a number makes no difference, I still receive the same Notices. I understand that its probably bad practice to use sequentially numbered variables but I haven't really been having much luck with arrays, I've only been learning php for 2 weeks, so please excuse my lack of knowledge. As I tried to explain I'm trying to understand how to call each part of the array, at the moment this is causing undefined notices. maybe it would help if I explained what I was trying to do, this file will be sending variables to dynamic text fields in flash that will display the questions and answers from my database.
  12. ok, I understand so how would I go about assigning each of these values to different variables? or should I be calling more than one field in each record?
  13. here is the full code //functions function get_id( $table) { $sql = mysql_query("select * FROM $table") ; while ($row =mysql_fetch_array($sql)) { return $row['ID']; } } function getquestions($id) { $sql =mysql_query("select text FROM questions WHERE quiz_ID =$id "); while($row = mysql_fetch_row($sql)) { return $row ; } } function getanswers() { $sql = mysql_query("select answer FROM answers WHERE question_ID= 1 "); while($row =mysql_fetch_row($sql)) { print_r (array_keys($row)); $ans1 = $row['0']; $ans2 = $row['1']; $ans3 = $row['2']; $ans4 = $row['3']; echo $ans1 . $ans2. $ans3. $ans4 ; } } //Connect to Database $con = mysql_connect("localhost","dinita","8888888"); if(!$con) { die('Could not connect: '.mysql_error()); } else { // SELECT DATABASE mysql_select_db("quizCreation", $con); ///Actual code $quizid = get_id("quizName", "ID"); $questionid = get_id("questions","quiz_ID"); if ($quizid == $questionid) { $question = getquestions("1"); echo $question[0]; getanswers(1); mysql_close($con); } }
  14. is it possible to store the keys of an array in to variables? currently my code looks like this: function getanswers() { $sql = mysql_query("select answer FROM answers WHERE question_ID= 1 "); while($row =mysql_fetch_row($sql)) { //print_r (array_keys($row)); $ans1 = $row['0']; $ans2 = $row; $ans3 = $row; $ans4 = $row; echo $ans1 . $ans2. $ans3. $ans4 ; } } and all I get are undefined offset notices what am i doing wrong? I'd appreciate any advice the output looks like this: The ‘Sea Swallow’ is an alternative name for which bird? Notice: Undefined offset: 1 in /Applications/MAMP/htdocs/Quiz/newfile.php on line 29 Notice: Undefined offset: 2 in /Applications/MAMP/htdocs/Quiz/newfile.php on line 30 Notice: Undefined offset: 3 in /Applications/MAMP/htdocs/Quiz/newfile.php on line 31 Seagull Notice: Undefined offset: 1 in /Applications/MAMP/htdocs/Quiz/newfile.php on line 29 Notice: Undefined offset: 2 in /Applications/MAMP/htdocs/Quiz/newfile.php on line 30 Notice: Undefined offset: 3 in /Applications/MAMP/htdocs/Quiz/newfile.php on line 31 Penguin Notice: Undefined offset: 1 in /Applications/MAMP/htdocs/Quiz/newfile.php on line 29 Notice: Undefined offset: 2 in /Applications/MAMP/htdocs/Quiz/newfile.php on line 30 Notice: Undefined offset: 3 in /Applications/MAMP/htdocs/Quiz/newfile.php on line 31 Tern Notice: Undefined offset: 1 in /Applications/MAMP/htdocs/Quiz/newfile.php on line 29 Notice: Undefined offset: 2 in /Applications/MAMP/htdocs/Quiz/newfile.php on line 30 Notice: Undefined offset: 3 in /Applications/MAMP/htdocs/Quiz/newfile.php on line 31 Cormorant Just in case it helps when I call the array keys they show this: Array ( [0] => 0 )Array ( [0] => 0 )Array ( [0] => 0 )Array ( [0] => 0 ) Thanks in advance to anyone who can help!
×
×
  • 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.