Jump to content

php_padawan

Members
  • Posts

    8
  • Joined

  • Last visited

Posts posted by php_padawan

  1. php is a server-side language. all the php code in a file runs on the server when the page gets requested. only the resulting output (html, javascript, media) is send to the browser.

     

    javascript is a client-side language. all the javascript code runs in the browser after it has been received by the browser.

     

    to get a value from javascript (in the browser) to php (on the server), you must send that value as part of a http request from the browser to the server. you can either send it as $_POST or $_GET data and if you don't want the page to refresh, you would use AjAX to send the http request.

     

     

    but the problem sir is that I am just doing a maintenance on a system. I have no way of modifying how the javascript is being handled and currently, the variable that I needed was coded in javascript as a variable.

  2. Hi Guys,

     

    Will you please help me with this?

     

    As from what you could see, the value of $bbbb is dynamic during runtime.  I am trying to get a value from a javascript variable to compare it against another variable in just true and false condition.  The problem is that it seems that php is not allowing a comparison between a php variable and javascript. no matter what I try, it can't bring the right output or the true and false from $bbbb

    is not working.  WHener I try to just put a simple true and false string to $bbbb, it works fine and normal.  the only problem is that whenever it has a value coming from javascript or '<script type="text/javascript">document.write(IsUserLoggedIn);</script>';

     

    I already tried the following:

     

    if ($bbbb == true) {

    if ($bbbb == 'true') {

    if ($bbbb ==  '<script type="text/javascript">document.write(IsUserLoggedIn);</script>'

     

     

    I am trying to fix this for a week, hope that someone could help me. thanks :)

     

    I really think that the problem lies in the part where I am trying to get the true and false value of a variable from a Javascript.  It is like I need to convert it to php string or something like that.

    $save_creation ='<a href="' . create_link( MENU_MYACCOUNT,'creations') . '\"> '.$CI->lang->line('glb_SaveSauvegarder').'creations'.'</a>';
    $dialog_box ='<a href="#" onclick="SignInDialog(\'\', \'\', \'' . create_link( MENU_MYACCOUNT) . '\'); return false;">'.$CI->lang->line('glb_SaveSauvegarder').' dialog_box'.'</a>';	    
    
                    
                $bbbb = '<script type="text/javascript">document.write(IsUserLoggedIn);</script>'; 
    
    
                if ($bbbb = true) {
                
                    	$return .= '</ul><span class="link">' .$save_creation. '</span></div>';
    	
    	         
    	                return $return;
                
                } else {
                
                	$return .= '</ul><span class="link">' . $dialog_box . '</span></div>';
    	
    	    
    	            return $return;
                
                
                }
    
  3. here is my most updated code, I have managed to connect to database and also return the data on the HTML page.  Still, my problem is how to compare two data to return the equivalent data on the third row but I am working on it.  I am still researching what is the best approach for this.

    <html>
    <head>
    	<title>JMData Decode</title>
    </head>
    <body>
    <?php
    $JMData = "{\"a_stepActual\":\"99\",\"a_StepReached\":\"99\",\"a_ShowBack\":\"1\",\"a_Similar\":\"\",\"a_JMStarted\":\"1\",\"a_GarmentStatus\":\"2\",\"s_Step1\":\"1\",\"s_Step2\":\"3\",\"s_Step3\":\"7\",\"s_Step4\":\"19\",\"s_Step4_s\":\"2\",\"s_Step5\":\"22\",\"s_Step5_s\":\"2\",\"s_Step6\":\"2816\",\"s_Step7\":\"2819\",\"s_Step8\":\"2821\",\"s_Step8_s\":\"2\",\"s_Step8_r\":\"3\",\"s_Step9\":\"36\",\"s_Step9_s\":\"0\",\"s_Step9_r\":\"0\",\"s_Step10\":\"2826\",\"s_Step10_s\":\"2\",\"s_Step10_r\":\"0\",\"s_Step11\":\"2830\",\"s_Step11_s\":\"2\",\"s_Step11_z\":\"0\",\"s_Step11_r\":\"3\",\"s_Step12\":\"2836\",\"s_Step12_s\":\"0\",\"s_Step12_z\":\"0\",\"s_Step12_r\":\"0\",\"s_Step13\":\"44\",\"s_Step13_s\":\"2\",\"s_Step13_z\":\"1\",\"s_Step13_b\":\"20\",\"s_Step14\":\"47\",\"s_Step14_s\":\"2\"}";
    
    $dec = (json_decode($JMData));
    
    echo "<table border = 1>";
                echo "<tr><td>First Row</td><td>Second Row</td><td>Third Row</td></tr>";
        foreach ($dec as $key => $value)
            {
                echo "<tr><td>". $key."</td><td>". $value ."</td><td>$nbsp</td></tr>";
            };
    echo "<table/>";
    ?>
    
    <?php
    $con=mysqli_connect("localhost","test","test","db_test");
    // Check connection
    if (mysqli_connect_errno())
      {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }
    
    $result = mysqli_query($con,"SELECT * FROM Step1Table");
    echo "</br></br>";
    echo "<table border = 1>";
    while($row = mysqli_fetch_array($result))
      {
      echo "<tr>
               <td>".$row['id']."</td>
               <td>".$row['StepWithoutQuotations']."</td>
               <td>".$row['StepValue']."</td>
               <td>".$row['StepWithQuotations']."</td>
               <td>".$row['InternalReference ']."</td>
           </tr>";    
      }
    echo "<table/>";
    mysqli_close($con);
    ?>
    
    
    </body>
    </html>
    
  4. Can you please help and advice me the best way to approach this requirement?

     

    As you can see, I have three columns.  The First Row, Second Row and Third Row.  I already managed to accomplish the First and Third Row, but this time, it is a bit challenging.  I need to match the data found in First and Second Row to come up with the Third Row.  I attached a copy of my table for your reference (testdb.txt).

     

    For example:

     

    If the value of the First Row is 's_Step1' and the Second Row is '1' the value of the Third Row should be 'Women'.

     

    If the value of the First Row is 's_Step2' and the Second Row is '3' the value of the Third Row should be 'Straight Women' and so on and so forth.

     

    Please guide me the best way to approach this.  Thanks :)

     

    Here is what I have accomplished so far:

     



    <html>
    <head>
    <title>JMData Decode</title>
    </head>
    <body>

    <?php
    $JMData = "{\"a_stepActual\":\"99\",\"a_StepReached\":\"99\",\"a_ShowBack\":\"1\",\"a_Similar\":\"\",\"a_JMStarted\":\"1\",\"a_GarmentStatus\":\"2\",\"s_Step1\":\"1\",\"s_Step2\":\"3\",\"s_Step3\":\"7\",\"s_Step4\":\"19\",\"s_Step4_s\":\"2\",\"s_Step5\":\"22\",\"s_Step5_s\":\"2\",\"s_Step6\":\"2816\",\"s_Step7\":\"2819\",\"s_Step8\":\"2821\",\"s_Step8_s\":\"2\",\"s_Step8_r\":\"3\",\"s_Step9\":\"36\",\"s_Step9_s\":\"0\",\"s_Step9_r\":\"0\",\"s_Step10\":\"2826\",\"s_Step10_s\":\"2\",\"s_Step10_r\":\"0\",\"s_Step11\":\"2830\",\"s_Step11_s\":\"2\",\"s_Step11_z\":\"0\",\"s_Step11_r\":\"3\",\"s_Step12\":\"2836\",\"s_Step12_s\":\"0\",\"s_Step12_z\":\"0\",\"s_Step12_r\":\"0\",\"s_Step13\":\"44\",\"s_Step13_s\":\"2\",\"s_Step13_z\":\"1\",\"s_Step13_b\":\"20\",\"s_Step14\":\"47\",\"s_Step14_s\":\"2\"}";

    $dec = (json_decode($JMData));

    echo "<table border = 1>";
    echo "<tr><td>First Row</td><td>Second Row</td><td>Third Row</td></tr>";
    foreach ($dec as $key => $value)
    {
    echo "<tr><td>". $key."</td><td>". $value ."</td><td>$nbsp</td></tr>";
    };
    echo "<table/>";

    ?>

    </body>
    </html>

    testdb.txt

  5. Start with unserialize

     

    Edit: or actually I think that's JSON? Try JSON_decode

     

     

    thanks for the advice.  using JSON is much simpler and cooler. many thanks!

     

    here is the final working code:

    <html>
    <head>
    	<title>JMData Decode</title>
    </head>
    <body>
    
    <?php
    $JMData = "{\"a_stepActual\":\"99\",\"a_StepReached\":\"99\",\"a_ShowBack\":\"1\",\"a_Similar\":\"\",\"a_JMStarted\":\"1\",\"a_GarmentStatus\":\"2\",\"s_Step1\":\"1\",\"s_Step2\":\"3\",\"s_Step3\":\"7\",\"s_Step4\":\"19\",\"s_Step4_s\":\"2\",\"s_Step5\":\"22\",\"s_Step5_s\":\"2\",\"s_Step6\":\"2816\",\"s_Step7\":\"2819\",\"s_Step8\":\"2821\",\"s_Step8_s\":\"2\",\"s_Step8_r\":\"3\",\"s_Step9\":\"36\",\"s_Step9_s\":\"0\",\"s_Step9_r\":\"0\",\"s_Step10\":\"2826\",\"s_Step10_s\":\"2\",\"s_Step10_r\":\"0\",\"s_Step11\":\"2830\",\"s_Step11_s\":\"2\",\"s_Step11_z\":\"0\",\"s_Step11_r\":\"3\",\"s_Step12\":\"2836\",\"s_Step12_s\":\"0\",\"s_Step12_z\":\"0\",\"s_Step12_r\":\"0\",\"s_Step13\":\"44\",\"s_Step13_s\":\"2\",\"s_Step13_z\":\"1\",\"s_Step13_b\":\"20\",\"s_Step14\":\"47\",\"s_Step14_s\":\"2\"}";
    $dec = (json_decode($JMData));
    
    echo "<table border = 1>";
        foreach ($dec as $key => $value)
            {
                echo "<tr><td>". $key."</td><td>". $value ."</td></tr>";
            };
                echo "<table/>";
    ?>
    
    </body>
    </html>
    
  6. I would like to request a little help from all of you.  I would like to know how can I approach this in php.

     

    I have this string of data:

     

    {"a_stepActual":"99","a_StepReached":"99","a_ShowBack":"1","a_Similar":"","a_JMStarted":"1","a_GarmentStatus":"2","s_Step1":"1","s_Step2":"3","s_Step3":"7","s_Step4":"19","s_Step4_s":"2","s_Step5":"22","s_Step5_s":"2","s_Step6":"2816","s_Step7":"2819","s_Step8":"2821","s_Step8_s":"2","s_Step8_r":"3","s_Step9":"36","s_Step9_s":"0","s_Step9_r":"0","s_Step10":"2826","s_Step10_s":"2","s_Step10_r":"0","s_Step11":"2830","s_Step11_s":"2","s_Step11_z":"0","s_Step11_r":"3","s_Step12":"2836","s_Step12_s":"0","s_Step12_z":"0","s_Step12_r":"0","s_Step13":"44","s_Step13_s":"2","s_Step13_z":"1","s_Step13_b":"20","s_Step14":"47","s_Step14_s":"2"}

     

    and I needed it to be converted to the attached file or be converted to a more readable format.

     

    post-154488-0-65392400-1369276352_thumb.png

     

    I tried looping to no success.

     

    Here is what I have done so far, by the way:

     




    <html>
    <head>
    <title>Test String</title>
    </head>
    <body>

    <?php
    $JMData = "{\"a_stepActual\":\"99\",\"a_StepReached\":\"99\",\"a_ShowBack\":\"1\",\"a_Similar\":\"\",\"a_JMStarted\":\"1\",\"a_GarmentStatus\":\"2\",\"s_Step1\":\"1\",\"s_Step2\":\"3\",\"s_Step3\":\"7\",\"s_Step4\":\"19\",\"s_Step4_s\":\"2\",\"s_Step5\":\"22\",\"s_Step5_s\":\"2\",\"s_Step6\":\"2816\",\"s_Step7\":\"2819\",\"s_Step8\":\"2821\",\"s_Step8_s\":\"2\",\"s_Step8_r\":\"3\",\"s_Step9\":\"36\",\"s_Step9_s\":\"0\",\"s_Step9_r\":\"0\",\"s_Step10\":\"2826\",\"s_Step10_s\":\"2\",\"s_Step10_r\":\"0\",\"s_Step11\":\"2830\",\"s_Step11_s\":\"2\",\"s_Step11_z\":\"0\",\"s_Step11_r\":\"3\",\"s_Step12\":\"2836\",\"s_Step12_s\":\"0\",\"s_Step12_z\":\"0\",\"s_Step12_r\":\"0\",\"s_Step13\":\"44\",\"s_Step13_s\":\"2\",\"s_Step13_z\":\"1\",\"s_Step13_b\":\"20\",\"s_Step14\":\"47\",\"s_Step14_s\":\"2\"}";
    //$JMData = "s_Step1":"1","s_Step2":"3","s_Step3":"7","s_Step4":"19","s_Step4_s":"2","s_Step5":"22","s_Step5_s":"2","s_Step6":"2816","s_Step7":"2819","s_Step8":"2821","s_Step8_s":"2","s_Step8_r":"3","s_Step9":"36","s_Step9_s":"0","s_Step9_r":"0","s_Step10":"2826","s_Step10_s":"2","s_Step10_r":"0","s_Step11":"2830","s_Step11_s":"2","s_Step11_z":"0","s_Step11_r":"3","s_Step12":"2836","s_Step12_s":"0","s_Step12_z":"0","s_Step12_r":"0","s_Step13":"44","s_Step13_s":"2","s_Step13_z":"1","s_Step13_b":"20","s_Step14;

    $JMData1 = str_replace("\"","",$JMData);

    $JMData2 = strpos($JMData1, "s_Step1");
    $JMData3 = substr($JMData1, strpos($JMData1, "s_Step1"), 500);

    //echo $JMData1;
    //echo $JMData2;
    echo $JMData3;

    ?>




    </body>
    </html>


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