Jump to content

strval rand problem


peter11

Recommended Posts

I have the following code:

 

Getting the Random text file:

$getfile = file("sentences/" .strval(rand ( 1 ,2 )).".txt"); 

 

Assigning vairables to each line:

$lines  = $getfile;
$i=1;
foreach($lines  as $line ){
   
   $var["line" . $i] = $line;
   $i++;
}
extract($var);

 

I am then echo'ing them:

echo ($line1)."<input type='text' size='4' name='q1' />".($line2);

 

i am then storing the date:

$message = ($line1).($q1).($line2);

 

I am then sending this data to facebook:

$facebook->api_client->stream_publish($message, $target_id);

 

However the problem is the Sentence from the file it takes and shows me (answering questions too) Is not always the same as the one it posts to facebook. I think it must be running this Random file twice however i dont think it should be. I cant understand why its different each time it should only call the random file once. Right?

 

Anyone know a way around this? Please help :)

 

Link to comment
Share on other sites

Let's simplify your code a little:

<?php
$lines = array_map('trim',file("sentences/" . rand(1 ,2) . ".txt")); 
echo $lines[0] . "<input type='text' size='4' name='q1' />" . $lines[1];
?>

 

Can you post the rest of your code, since you're obviously generating a form, but I don't see the <form> statement, so I don't know how your assigning the variable $q1.

 

Ken

Link to comment
Share on other sites

There is a lot of code. Yes the form stuff is at the bottom.

 

if it helps.

 

echo "<form method='post'>";
echo ($line1)."<input type='text' size='4' name='q1' />".($line2);

echo "<p><input class='submitbox' type='submit' value='Answer and Publish'></form>";

echo "</table>";

Link to comment
Share on other sites

If you're not using the variable $message in more than one place, you can do

<?php
$facebook->api_client->stream_publish($lines[0] . $_POST['q1'] . $lines[1]), $target_id);
?>

 

Also, you really should put an action attribute in the <form> tag:

<?php
echo "<form method='post' action=''>";
?>

 

Ken

Link to comment
Share on other sites

Here is the code related in order:

 

<?php
$getfile = file("sentences/" .strval(rand ( 1 ,2 )).".txt");  

$lines  = $getfile;
$i=1;
foreach($lines  as $line ){
   
   $var["line" . $i] = $line;
   $i++;
}
extract($var);

echo "<form method='post' action=''>";
echo ($line1)."<input type='text' size='4' name='q1' />".($line2);
echo "<p><input class='submitbox' type='submit' value='Answer and Publish'></form>";

$q1 =  $_POST["q1"];

// Post MSG on users profile 
if ($q1 == ""){
echo "<p></p><div class='error1'>ENTER SOMETHING !!</div>";
}
else 
$facebook->api_client->stream_publish($lines[0] . $_POST['q1'] . $lines[1]. $target_id);
?>

 

If anyone knows they this is posting the random question to the profile different to the one it asks you please help :)

Link to comment
Share on other sites

I have noticed when doing this If you answer the question it will then load the page again with random question again when u click submit it always seems to give the next question as the one it posts not the one you clicked submit too.

 

So therefor i need to make sure the code has ended and starts again when clicking "submit and post" I have tryed doing this was sessions however that dont work.

 

Anyone know how to do this?

Link to comment
Share on other sites

I have re-done the code but put this in switches. Again it is doing the same. Posting the next question it asks you and not the one you answered

 

Therefor it is a problem with

<?php $facebook->api_client->stream_publish($part1 . $_POST['q1'] . $part2).($target_id); ?>

 

It needs to run this with the $part1 and $part2 as the one it asks you and not the next one when you click submit. In the code submit is below this line of code.

 

The form look like the following:

<?php
echo "<form method='post' action='http://apps.facebook.com/missingwords/'>";
echo ($part1)."<input type='text' size='4' name='q1' />".($part2);
echo "<p><input class='submitbox' type='submit' value='Answer and Publish'></form>";
?>

 

Anyone have any idea how to do this?

 

HELPPPP :)

 

Link to comment
Share on other sites

I have tried using

 

$facebook->api_client->stream_publish($message);  AND Facebook.streamPublish(message,attachment,action_links);

 

Both work fine however have the same problem.

 

I am pulling up a random file also tried with a random switch and i want to post that random switch or file.

This does work however it posts the wrong one.

 

I.e If the switch was "whats your name" and you answered it and clicked publish it would then load the page again and maybe ask you "whats your age" it would have posted the whats you name answer you gave with whats your age.

 

Does anyone know a way around this? Im out of ideas please help

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.