/    Sign up×
Community /Pin to ProfileBookmark

Array problem/confusion

I’ve made a little system/mod (names vary) which lists things in the order of

Topic
–Category
—–Item

and there are varied results for this and for each of the 3 they have a small box for a number to tell them their display order (1 = display first, etc.) and its all in a form the display order for topics is order-f, for categories is order-c and for items; order-i, and when I press submit (its all in a form) the next page prints the array and all I get is

[QUOTE]

Array
(
[order-f] => Array
(
)

[order-c] => Array
(
)
[order-i] => Array
(
)

)

[/QUOTE]

There are more than 1 result and the results are empty and I’ve no idea why, they are parsed through the url using $_GET but I used vbulletin so I have to use an input cleaner which does the same without any problems and I defined them as arrays in the cleaner and I’ve no idea why it doesn’t print anything.

Help?? (or questions about what the hell I’m talking about because my explaining sucks xD)

to post a comment
PHP

11 Comments(s)

Copy linkTweet thisAlerts:
@sstalderMar 11.2008 — Post the code for your form and PHP.
Copy linkTweet thisAlerts:
@James32authorMar 11.2008 — ok gonna have to cut it down abit though. (its a big file)

[code=php]
<form action="favorites.php?do=displayorder" method="post" name="dorder" id="cpform">
<?php
$mains = get_mains(); // puts all mains in array $mains
$cats = get_cats(); // puts all cats in array $mains
$items = get_items(); // puts all items in array $mains


if(!isset($items) or empty($items))
{
$items = array();
}

if(!isset($cats) or empty($cats))
{
$cats = array();
}

foreach($mains as $main) {


// Define Favorite Variables
$fid = $main['favid'];
$fname = $main['name'];
$fdo = $main['displayid'];

// Generate List of Favorites
?>
<table cellpadding="2" cellspacing="1" width="100%" align="center" border="0">
<tr valign="top" align="center">
<td class="thead" align="left" width="50%">Favorite</td>
<td class="thead" width="10%">Display Order</td>
<td class="thead" width="40%" align="left">Controls</td>
</tr>
</table>
<table cellpadding='4' cellspacing='0' width='100%' border='0' class='tcat'>
<tr>
<td width='50%'><strong><a href='#'><?php echo $fname; ?></a></strong></td>
<td width='10%'><div class="smallfont" style='float:right;'>
<input type='text' class='bginput' name='order-f' value='<?php echo $fdo; ?>' tabindex='1' size='3' title='Display Order' />
</div></td>
<td class="smallfont" width="40%">
<div style="float: right;">
<a href="favorites.php?do=addcat&id=<?php echo $fid; ?>&name=<?php echo $fname; ?>"><strong>[Add Cat]</strong></a>
</div>
<a href="favorites.php?do=editfav&id=<?php echo $fid; ?>&name=<?php echo $fname; ?>"><strong>[Edit Fav]</strong></a>
<a href="favorites.php?do=deletefav&id=<?php echo $fid; ?>&name=<?php echo $fname; ?>"><strong>[Delete Fav]</strong></a>
</td>
</tr>
</table> <?php

foreach($main['cats'] as $cat) {

// Define Categories Variables
$cid = $cat['catid'];
$cname = $cat['catname'];
$cdo = $cat['displayid'];
$cmain = $cat['favid'];

// Generated List of Categories
?> <table cellpadding='2' cellspacing='1' width='100%' border='0'>


<tr valign="middle" align="center">
<td class="thead" align="left" width="50%"><div class="col1">&nbsp;<a href='#'><?php echo $cname; ?></a></div></td>
<td class="thead" width="10%">
<div style='float:right;'>
<input type='text' class='bginput' name='order-c' value='<?php echo $cdo; ?>' tabindex='1' size='3' title='Display Order'/>
</div>
</td>
<td class="thead" width="40%" align="left">
<div style="float: right;">
<a href="favorites.php?do=additem&catid=<?php echo $cid; ?>&catmain=<?php echo $cmain; ?>"><strong>[Add Item]</strong></a>
</div>
<a href="favorites.php?do=editcat&catid=<?php echo $cid; ?>&catmain=<?php echo $cmain; ?>"><strong>[Edit Cat]</strong></a>
<a href="favorites.php?do=deletecat&catid=<?php echo $cid; ?>&catmain=<?php echo $cmain; ?>"><strong>[Delete Cat]</strong></a>
</td>
</tr>
</table><?php

foreach($cat['items'] as $item) {

// Define Item Variables
$icid = $item['catid'];
$iname = $item['itemname'];
$itemid = $item['itemid'];
$imain = $item['mainid'];
$ido = $item['displayid'];


// Generated list of Items
?><table cellpadding='4' cellspacing='0' width='100%' border='0' class='alt2'>
<tr>
<td width='50%'>&nbsp;&nbsp;<span class="smallfont"><strong>----</strong></span> <strong><a href='#'><?php echo $iname; ?></a></strong></td>
<td width='10%'><div style='float:right;'>
<input type='text' class='bginput' name='order-i' value='<?php echo $ido; ?>' tabindex='1' size='3' title='Display Order' />
</div></td>
<td class="smallfont" width="40%">
<a href="favorites.php?do=edititem&itemid=<?php echo $itemid; ?>&cat=<?php echo $icid; ?>&imain=<?php echo $imain; ?>"><strong>[Edit Item]</strong></a>
<a href="favorites.php?do=deleteitem&itemid=<?php echo $itemid; ?>&cat=<?php echo $icid; ?>&imain=<?php echo $imain; ?>"><strong>[Delete Item]</strong></a>

</td>
</tr>
</table><?php

}
}
echo '<table class="alt2" align="center" width="100%" cellpadding="0" cellspacing="0">';
print_hr_row();
echo '</table>';
}?>
<table cellpadding="2" cellspacing="0" border="0" width="100%" class="tborder" style="border: 0px" align="center">
<tr>
<td class="tfoot" align="center">
<input type="button" class="button" tabindex="1" value="New Favorite" onclick="window.location='favorites.php?<?php echo $vbulletin->session->vars['sessionurl_js']; ?>do=addfav';" />&nbsp;<input type="submit" class="button" tabindex="1" value="Save Display Order" accesskey="s" />
</td>
</tr>
</table></form>[/code]


The functions called just compile mains, cats & items.
Copy linkTweet thisAlerts:
@sstalderMar 11.2008 — Can I see these functions?

$mains = get_mains(); // puts all mains in array $mains

$cats = get_cats(); // puts all cats in array $mains

$items = get_items(); // puts all items in array $mains
Copy linkTweet thisAlerts:
@sstalderMar 11.2008 — What I am not seeing is where you are building those arrays?
Copy linkTweet thisAlerts:
@James32authorMar 11.2008 — ok

[code=php]function get_mains() {
global $vbulletin, $db;

$mains_query = $vbulletin->db->query_read("SELECT favid, name, displayid FROM " . TABLE_PREFIX . "favs_main ORDER BY displayid");
while($record = $db->fetch_array($mains_query)) {
$mains[$record['favid']] = $record;
$mains[$record['favid']]['cats'] = array();
}

return $mains;
}

function get_cats() {
global $vbulletin, $db;

$cats_query = $vbulletin->db->query_read("SELECT catid, favid, catname, displayid FROM " . TABLE_PREFIX . "favs_cats ORDER BY displayid");
while($record = $db->fetch_array($cats_query)) {
$cats[$record['catid']] = $record;
$cats[$record['catid']]['items'] = array();
}

return $cats;
}

function get_items() {
global $vbulletin, $db;

$item_query = $vbulletin->db->query_read("SELECT itemid, catid, itemname, itemurl, displayid, mainid FROM " . TABLE_PREFIX . "favs_items ORDER BY displayid");
while($record = $db->fetch_array($item_query)) {
$items[$record['itemid']] = $record;
}

return $items;
}
[/code]



Building the array? thats where I get puzzled. :/
Copy linkTweet thisAlerts:
@James32authorMar 12.2008 — 24 Bump.
Copy linkTweet thisAlerts:
@James32authorMar 14.2008 — Bumping . . . again. *waits for sstalder*
Copy linkTweet thisAlerts:
@sstalderMar 15.2008 — Instead of

$mains = get_mains(); // puts all mains in array $mains

$cats = get_cats(); // puts all cats in array $mains

$items = get_items(); // puts all items in array $mains

Try to print your arrays to see if they are not empty:

print_r(get_mains());

print_r(get_cats());

print_r(get_items());

If they are empty then we need to look at the functions themselves.
Copy linkTweet thisAlerts:
@James32authorMar 15.2008 — It printed this mass of stuff.

Array ( [35] => Array ( [favid] => 35 [name] => TV Show [displayid] => 1 [cats] => Array ( ) ) ) Array ( [21] => Array ( [catid] => 21 [favid] => 35 [catname] => Magical [displayid] => 1 [items] => Array ( ) ) [22] => Array ( [catid] => 22 [favid] => 35 [catname] => Drama [displayid] => 2 [items] => Array ( ) ) ) Array ( [19] => Array ( [itemid] => 19 [catid] => 22 [itemname] => The OC [itemurl] => 0 [displayid] => 1 [mainid] => 35 ) [17] => Array ( [itemid] => 17 [catid] => 21 [itemname] => Charmed [itemurl] => 0 [displayid] => 1 [mainid] => 35 ) [18] => Array ( [itemid] => 18 [catid] => 21 [itemname] => Supernatural [itemurl] => 0 [displayid] => 2 [mainid] => 35 ) )[/quote]

That is just the results of what the function does which is apply a parenting system. *is stumped*
Copy linkTweet thisAlerts:
@James32authorMar 18.2008 — Bump.
Copy linkTweet thisAlerts:
@James32authorMar 21.2008 — And . . .bump (again)

Help, anyone?
×

Success!

Help @James32 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...