Jump to content

Nodral

Members
  • Posts

    397
  • Joined

  • Last visited

Posts posted by Nodral

  1. Hi

     

    I need to draw a line graph with php which must include negative co-ordinates.  I've looked online for pre-packed applications but can't get on with them.  Can anyone recommend a tutorial for a php beginner to do this?

  2. Hi All

     

    I'm getting a header error on the code given and having read the sticky on this forum cannot find where the error is and why my page won't redirect.

     

    Any ideas?

     

    connect.php

    <?php
    $link = mysql_connect('localhost', '****', '********');
    if (!$link)
    {
    echo'1Unable to connect to the database server.';
    
    exit();
    }
    
    if (!mysql_set_charset('utf8', $link))
    {
    echo'2Unable to connect to the database server.';
    
    exit();
    }
    
    if(!mysql_select_db('******', $link))
    {
    echo'3Unable to connect to the database server.';
    
    exit();
    }
    
    ?>

     

    index.php

    <?php
    $host  = $_SERVER['HTTP_HOST'];
    $uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
    
    //set variables from login form below
    if(strlen($_POST['username'])>1){
    $username=$_POST['username'];
    }
    
    if(strlen($_POST['password'])>1){
    $password=$_POST['password'];
    }
    
    $register=$_POST['register'];
    $forgotten=$_POST['forgotten'];
    
    
    //log the user in or create an acct for learning styles
    include_once("connect.php");
    ?>
    <form method="POST" action="">
    <p>Username <input type="text" name="username" size="40"></p>
    <p>Password <input type="password" name="password" size="40"></p>
    <p><input type="submit" value="Login">
    <p>If you have not previously completed this questionnaire, please click the 'Register' button below, alternatively if you have forgotten your login details please click the 'Forgotten Login' button.</p>
    <p><input type="submit" name="register" value="Register">   <input type="submit" name="forgotten" value="Forgotten Login"></p>
    </form>
    <?php
    
    if(isset($username, $password)){
    //log user in
    //include("login.php");
    
    
    }
    
    elseif(isset($register)){
    //divert to reg form
    $extra = 'register.php';
    header("Location: http://$host$uri/$extra");
    
    }
    
    elseif(isset($forgotten)){
    //ask for email address and send mail of details
    //include("forgotten");
    }
    
    elseif((isset($username) and !isset($password)) or (!isset($username) and isset($password))){
    //give message of details req
    echo "no details";
    }
    ?>

     

    Error  -Warning: Cannot modify header information - headers already sent by (output started at D:\Documents\AI24\Web\skooch\learning_styles\index.php:26) in D:\Documents\AI24\Web\skooch\learning_styles\index.php on line 40

     

    Any ideas anyone?

     

  3. Hi

     

    I'm writing a questionnairre where a user has to answer 50 questions either yes or no.  The questions are stored in a db and displayed on screen using an array of questionid -> questiontext.  I cna make this display with 2 radio buttons (yes or no) but each one of these lines would need to be an individual form.  I would need just one submit button at the end to then write the answers back into my db.

     

    How do I make a submit button return several forms?  or is there a better way of doing this?

     

    <?php
    $sql="SELECT id, text FROM ls_questions";
    $sql=mysql_query($sql);
    $count=mysql_num_rows($sql);
    while($row=mysql_fetch_array($sql)){
    $all_questions[$row['id']]=$row['text'];
    }
    
    //print them on the screen with a yes/no radio button 
    ?>
    <p>
    <table width="80%">
    <?php
    echo "$table_header";
    while(list($id, $text)=each($all_questions)){
    	echo'<tr><form method="POST" action=""><td>' . $text . '</td><td><input type="radio" name="' . $id . '" value="yes"></td><td><input type="radio" name="' . $id . '" value="no"></td></form></tr>';
    }
    ?>
    <form><input type="submit"></form>

  4. Hi Guys

     

    I've absolutely no knowledge of OOP and I've inherited a huge site built with OOP.  I can convert some of it, to variables I understand and can use, and have a vague understanding of the predefined functions.  However I an struggling to put a simple if/or statement together.

     

    if(user_has_role_assignment($USER->id,1)){

     

    works fine, but when I try to do it as an if / or it fails.

     

    if(user_has_role_assignment($USER->id,1)) || ($USER->id,36))  {

     

    Any ideas?

     

    Sorry, I don't have any errors as another part of the site turns off the error reporting and I can't for the life of me turn it back on with error_reporting(E_ALL) in the page;

  5. Hi

     

    Do it as 2 seperate queries.

     

    $sql="SELECT lastname, firstname, email FROM table1 WHERE email='someemail@gmail.com' ";
    $sql=mysql_query($sql) or die();
    while($row=mysql_fetch_array($sql){
    $name=$row['lastname'] . $row['firstname'];
    }
    
    $sql="INSERT INTO table2 " .  $name;
    mysql_query($sql) or die();

     

     

     

     

     

  6. I don't really understand the function you've written.  Where do I declare the $a and $b values in my code and how does it work?  As I said, I'm a complete newbie and I'm the sort of person who like to know WHY things work so I can customize them for future use.

     

    The array is structured in that way as the next step is to output to a table which will have a column for username, a column for the score and then a column of radio buttons (with the return value for each as the userid).

     

    When the table is viewed, the users can select the radio button and this will then take them to a question by question breakdown of their score by requesting the information from a database where the user responses are held against userid.

     

    Is it possible to make the function generic so I can hold it in a library and call it into further scripts, as I get the feeling it may be very useful.

     

     

     

     

  7. Hi All

     

    I'm new to php and I have a multidimensional array set up which I need to sort for a results list from an assessment.

     

    The array is $gradout['name']['userid']=score.

     

    I need to sort the array by score in a decending order. 

     

    ['name'] is a string and ['userid'] is a numeric.

     

    I've tried looking at the php manual but It's just confusing me.  Can anyone explain to me in laymans terms what I need to do and why.

  8. Hi

     

    Could there be a typo in these 2 lines?

    $query = "SELECT * FROM publications WHERE member_id ='".$_SESSION['id']."' AND cartegory='status'";

     

    $query = "INSERT INTO publications ( member_id, publication, cartegory, pub_date) VALUES ( '{$_SESSION['id']}','{$_POST['limitedtextfield']}', 'status', NOW() )";

     

    Should it not be category?  Obviously I'm not sure about your tables, but this would seem logical?

     

    Also you're missing concatenating full stops in the 2nd line.  I'd guess at

     

    $query = "SELECT * FROM publications WHERE member_id ='".$_SESSION['id']."' AND category='status'";

     

    And

     

    $query = "INSERT INTO publications ( member_id, publication, cartegory, pub_date) VALUES ( ' . {$_SESSION['id']} . ',' . {$_POST['limitedtextfield']} . ', 'status', NOW() )";

     

     

     

  9. Try this

     

    Use curly braces instead of colon and endwhile;, and lose the pointless else{}'s

     

    if(isSet($_GET['answer'])) {
    $answ = $_GET['answer'];
    $nextanswer=$answ+1;
    } 
    else{}
    $counter2 = 1;
    while ($counter2 <= $answ){        
    	echo $Answer[$counter2]."<br>";
    	$counter2++;
    }
    	if($nextansw>0){   
    		if(isset($Answer[$nextanswer])){
    			echo "<a href=\"/Code-sandbox.php?sid=".$name."&answer=".$nextanswer."\">next</a>";
    			}    else{
    				echo "End of questions<br>";
    			}
    	}
    

     

     

  10. Cheers for that.

     

    Ok, as you suggest keeping it in one array, I need to provide an HTML table with columns REGION, COUNT of userids, Average value.

    I then need to add a total at the bottom totalling count of all userid and an average of value.

     

    Is this possible?

     

    Sorry, I'm a newbie and been playing with this for a couple of days and getting nowhere fast.

     

    Cheers

  11. Hi All

     

    How do I go about splitting a multidimensional array into seperate smaller ones?

     

    Currently I have $grade[region][userid]=value.

     

    I'd like to split as

    • $region1[userid]=value
    • $region2[userid]=value
    • $region3[userid]=value
    • $region4[userid]=value
    • $region5[userid]=value
    • $region6[userid]=value
       

     

    Is there an inbuilt function for this?

  12. I seem to be able to either get all the content in column 1 of the table or all in 1 row for all id's.

     

    I want each id on it's own line in the table.  I just don't seem to be able to get the <tr> tags to appear in the correct place when foreaching the info out.

  13. Hi All

     

    Please see code below.  I cannot get my table to produce correctly.  I have a multidimensional array $data['id']['fieldid']=$row['content']

    I want this to loop through and create a new line in a table for each sub-array.  hence the table would look like this.

     

    (id1 in this row) 

    field1 content 

    field2 content 

    field3 content 

    field4 content 

    (id2 in this row) 

    field1 content 

    field2 content 

    field3 content

    field4 content 

    (id3 in this row) 

    field1 content 

    field2 content 

    field3 content 

    field4 content 

    (id4in this row) 

    field1 content 

    field2 content 

    field3 content 

    field4 content 

    etc etc.  The table can grow or shrink depending on the data I'm retrieving.

     

    <table><font size="8">
    <tr>
    <?php
    foreach ($header_out as $value){
    echo "<td>$value</td>";
    }
    ?>
    
    </tr>
    <?php
    echo"<tr>";
    foreach($data as $value){
    $count++;
    	foreach($value as $dataout){
    	echo "<td>$dataout $count</td>";
    }
    
    }echo"</tr><tr>";
    ?>
    </tr></font></table>
    
    <?php } ?>

     

    The header section works fine, but the double foreach loop seems to be where I'm failing.

     

    Any advice guys?

  14. Hi

     

    I have a database which has been built by another party and they have used a field called param1 which contains all the details from a prepopulated dropdown list.  This is then referenced by number from another field (fieldid) in another table to get the single result.  How do I go about replicating this to get one answer?

     

    eg

     

    Param1 = Thailand Tunisia Turkey Ukraine United Arab Emirates United Kingdom United Kingdom - Islands - Guernsey United Kingdom - Islands - Jersey United Kingdom - Islands - Isle of Man Virgin Islands

     

    fieldid = 6

     

    hence this returns United Kingdom.

     

    How can I split all the options out.  I thought about returning all entries and pattern matching, but as you can see there are some results which would contain capitals in vaiours places or speaces etc within the field.

     

    I'm stumped!!!

     

    Any ideas?  I can't change the way the database, but I need to be able to get the information out in a usable format.

     

    Stu

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