PDA

View Full Version : Warning: Cannot use a scalar value as an array



pkcidstudio
04-21-2007, 01:34 PM
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
//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();
?>
__________________

boxxertrumps
04-21-2007, 01:44 PM
// Count table rows
$count=mysql_num_rows($result);
$id = array();
?>

You have to declare a variable as an array before assigning values.

pkcidstudio
04-23-2007, 02:40 PM
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?

boxxertrumps
04-23-2007, 09:23 PM
Is the live version having values changed, that need to be updated?
i mean, it wont be updated if there aren't any changes...

pkcidstudio
04-24-2007, 01:03 PM
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:

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.

pkcidstudio
04-24-2007, 06:25 PM
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
//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>");
}
}
?>

boxxertrumps
04-24-2007, 06:44 PM
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>");

pkcidstudio
04-24-2007, 06:57 PM
Close, now instead of displaying the file name is displaying
title
Array
title
Array
title
Array
Array
Array
Array
Array

boxxertrumps
04-24-2007, 08:17 PM
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[#]...

pkcidstudio
04-24-2007, 08:29 PM
very interesting!
(I needed to change the name of the pdf files for privacy purposes.)
here is a sample of the output:

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:

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>";
}

boxxertrumps
04-24-2007, 08:51 PM
echo "<a href='$path/$folder/$doc'>".$data['doc']."</a></br>";
}
echo "<br>";

Hope that's what you want...

pkcidstudio
04-24-2007, 09:07 PM
Thats it.
Thank you for your assistance.

Abhi Kalyan
02-14-2013, 11:36 AM
Declare the array. The error gets removed once you declare the array. In the following example we declare field as an array before declaring the array.
<?php
$field = array();
$field[0]="monkey";
$field[1]="donkey";
$field[2]="hockey";
$hockey = 173;
print "My " . $field[0] . " is " . ${$field[2]} . " years old";
?>