Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Warning: Cannot use a scalar value as an array

  1. #1
    Join Date
    Jun 2006
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Warning: Cannot use a scalar value as an array

    Found a solution, but recieving a error
    ERROR:
    Warning: Cannot use a scalar value as an array in SYS:/apache2/folder/folder/folder/folder/folder/updatedDocument3.php on line 64
    61-thats the id number for that row-
    This error comes up for every row, and then displays the row number like i ask it to.
    Could someone please look at this and let me know what you think. I have not seen this error prior.

    PHP Code:
    <?php
     
    //This include links to the connection to the database, which holds the following function | connectToDB();
     
    include('_admin/connectToDB.php');
     
    // This is closeing the database connection
     
    connectToDB();
     
    //The table we are choosing to connect to
     
    $tbl_name "table";
    ?>
     
    <div>
     <img border="0" src="images/manuals.jpg"><br><img border="0" src="images/home.jpg" >
     <p>Product Manual Maintence | Updated Document Page</p>
     
     <!-- Sections For Product Manual Maintenance -->
     
      <!-- Submitting the Form -->
      <!-- Selection of Latest Document -->
         <?php
          $sql
    ="SELECT * FROM $tbl_name";
          
    $result=mysql_query($sql);
     
          
    // Count table rows 
          
    $count=mysql_num_rows($result);
         
    ?>
         <table cellpadding=1 cellspacing=0 border=1 valign="top">
          <form name="form1" method="post" action="">
         <p><b>Latest Document:</b><br>info:</p>
     
          <tr>
           <td colspan=8 bgcolor="#999900" align=center><font color="white"><b>subject</b></font></td>
          </tr>
          <tr>
           <!--categories-->
           <td width=1%><font size=-2><b>ID</b></font></td>
           <td width=15%><font size=-2><b>Title</b></font></td>
           <td width=9%><font size=-2><b>File Name</b></font></td>
           <td width=35%><font size=-2><b>Document</b></font></td>
           <td width=8%><font size=-2><b>version</b></font></td>
           <td width=15%><font size=-2><b>Last Updated</b></font></td>
           <td width=8%><font size=-2><b>Document Hidden</b></font></td>
           <td width=8%><font size=-2><b>Title Hidden</b></font></td>
          </tr>
         <?php
         
    while($rows=mysql_fetch_array($result)){
         
    ?>
          <tr>
           <td align="center"><? $id[]=$rows['id']; ?><? echo $rows['id']; ?></td>
           <td align="center"><input name="title[]" type="text" id="title" value="<? echo $rows['title']; ?>"></td>
           <td align="center"><input name="filename[]" type="text" id="filename" value="<? echo $rows['filename']; ?>"></td>
           <td align="center"><input name="document[]" type="text" id="document" value="<? echo $rows['document']; ?>"></td>
           <td align="center"><input name="version[]" type="text" id="version" value="<? echo $rows['version']; ?>"></td>
           <td align="center"><input name="date[]" type="text" id="date" value="<? echo $rows['date']; ?>"></td>
           <td align="center"><input name="documenthide[]" type="text" id="documenthide" value="<? echo $rows['documenthide']; ?>"></td>
           <td align="center"><input name="titlehide[]" type="text" id="titlehide" value="<? echo $rows['titlehide']; ?>"></td>      </tr>
          </tr>
         <?php
         
    }
         
    ?>
         <tr>
         <td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td>
         </tr>
     
         </form>
         </table>
         <?php
         
    // Check if button name "Submit" is active, do this 
         
    if($Submit){
         for(
    $i=0;$i<$count;$i++){
         
    $sql1="UPDATE $tbl_name SET
             title='
    $title[$i]', 
             filename='
    $filename[$i]', 
             document='
    $document[$i]
             version='
    $version[$i]', 
             date='
    $date[$i]', 
             documenthide='
    $documenthide[$i]',
             titlehide='
    $titlehide[$i]',
                 WHERE id='
    $id[$i]'";
         
    $result1=mysql_query($sql1);
         }
         }
     
         if(
    $result1){
         echo 
    'working';
         }
         
    mysql_close();
         
    ?> 
    __________________

  2. #2
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    // Count table rows
    $count=mysql_num_rows($result);
    $id = array();
    ?>

    You have to declare a variable as an array before assigning values.
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

  3. #3
    Join Date
    Jun 2006
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks Boxxertrumps,
    That took away the error. for some reason the same exact code updates my test version, but will not update my live version. any thoughts?

  4. #4
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Is the live version having values changed, that need to be updated?
    i mean, it wont be updated if there aren't any changes...
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

  5. #5
    Join Date
    Jun 2006
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks boxxertrumps.
    I found this and think it will be very helpful to people. Great tutorial here.
    http://www.theblog.ca/?p=12

    Does any one have an idea on generate the following with a select stmt?
    EXAMPLE:
    HTML Code:
    Title
    doc 
    doc
    doc
    
    Title
    doc
    
    Title
    doc
    doc 
    doc
    Basically what is shown above is there will be one DISTINCT title and then under it any files associated with that title.

  6. #6
    Join Date
    Jun 2006
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I have this, which does what I want it to do, but instead of printing the name of the file it is generating a number
    title
    0
    title
    0
    1
    2
    3
    title
    0
    2
    ...


    any thoughts of why this is happening?
    PHP Code:
    <?php
    //Select title from a drop down, and allow title deletion (The titlehide flag is set to 1)
    //select the titles that are different

    $query "SELECT * FROM $tbl_name WHERE titlehide='no' ORDER BY title";
    $result mysql_query($query) or die("Invalid query: $query");
    if(
    mysql_num_rows($result) == 0)
    {
    echo 
    "No locations exist";
    }
    else
    {
    while(
    $row mysql_fetch_array($result))
    {
    $available_titles[$row["title"]][] = array('url' => $row['url'], 'doc' => $row["document"]);
    $path 'http://foo/foo2/bar/bar2';
    $folder $row['url'];
    $doc $row['document'];
    }
    }
    foreach(
    $available_titles as $title => $tmp)
    {
    echo 
    $title."<br>";
    foreach(
    $tmp as $doc => $data)
    {
    print_r("<a href='$path/$folder/$doc'>".$doc."</a></br>");
    }
    }
    ?>

  7. #7
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    foreach($tmp as $doc => $data)
    {
    print_r("<a href='$path/$folder/$doc'>".$doc."</a></br>");

    $doc is the key, i think you'd want:

    foreach($tmp as $doc => $data)
    {
    print_r("<a href='$path/$folder/$doc'>".$data."</a></br>");
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

  8. #8
    Join Date
    Jun 2006
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Close, now instead of displaying the file name is displaying
    title
    Array
    title
    Array
    title
    Array
    Array
    Array
    Array
    Array

  9. #9
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Ok... Please use this:
    foreach($tmp as $doc => $data)
    {
    echo "<a href='$path/$folder/$doc'>".print_r($data)."</a></br>";

    And give me the output... I need to know what key to use in the array so that the proper data is outputted with $data[#]...
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

  10. #10
    Join Date
    Jun 2006
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    very interesting!
    (I needed to change the name of the pdf files for privacy purposes.)
    here is a sample of the output:
    Code:
    Aergo
    Array ( [url] => Aergo [doc] => the correct file.pdf ) 1
    
    Beta Max
    Array ( [url] => Beta Max [doc] => this is the correct file.pdf ) 1
    Array ( [url] => Beta Max [doc] => thats the correct file.pdf ) 1
    Section:
    PHP Code:
    while($row mysql_fetch_array($result))
    {
    $available_titles[$row["title"]][] = array('url' => $row['url'], 'doc' => $row["document"]);
    }
    foreach(
    $available_titles as $title => $tmp)
    {
    echo 
    $title."<br>";
    foreach(
    $tmp as $doc => $data)
    {                            
    $path 'http://foo/foo2/bar/bar2';
    $folder $row['url'];
    $doc $row['document'];
    echo 
    "<a href='$path/$folder/$doc'>".print_r($data)."</a></br>";
    }
    echo 
    "<br>";


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •